Попытка создать математическую панель ввода в C #

StackOverflow https://stackoverflow.com/questions/1623378

Вопрос

Как мне создать панель математического ввода в 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;
}

Я вызываю функцию dll в C #, и панель всплывает, но сразу исчезает. Есть предложения?

Это было полезно?

Решение

В своем проекте 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