6

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 関数を呼び出すと、パネルがポップアップしますが、すぐに消えます。助言がありますか?

4

1 に答える 1

8

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();
        }
    }
}
于 2009-10-26T06:52:58.527 に答える