質問

C#で数学入力パネルを作成するにはどうすればよいですか?

それをdllに入れて呼び出しようとしましたが、すぐに閉じます。

#include <stdafx.h>
#include <atlbase.h>
#include "micaut.h"
#include "micaut_i.c"

extern "C" __declspec(dllexport) int run()
{
   CComPtr<IMathInputControl> g_spMIC; // Math Input Control
   HRESULT hr = CoInitialize(NULL);
   hr = g_spMIC.CoCreateInstance(CLSID_MathInputControl);
   hr = g_spMIC->EnableExtendedButtons(VARIANT_TRUE);
   hr = g_spMIC->Show();

   return hr;
}

C#でdll関数を呼び出すと、パネルがポップアップしますが、すぐに消えます。提案はありますか?

役に立ちましたか?

解決

C#プロジェクトで、COMライブラリー micautLib への参照を追加します。その後、次のコードを使用できます(C#で):

MathInputControl ctrl = new MathInputControlClass();
ctrl.EnableExtendedButtons(true);
ctrl.Show();

これが正確にあなたがそれを行うはずであるかどうかはわかりませんが、これはきれいに動作するようです(完全なプログラム)。

using System;
using System.Windows.Forms;
using micautLib;

namespace MathInputPanel
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MathInputControl ctrl = new MathInputControlClass();
            ctrl.EnableExtendedButtons(true);
            ctrl.Show();
            ctrl.Close += () => Application.ExitThread();
            Application.Run();
        }
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top