【问题标题】:Trying to create a Math Input Panel in C#尝试在 C# 中创建数学输入面板
【发布时间】:2010-12-10 01:13:56
【问题描述】:

如何在 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# c++ dll windows-7 dllimport


    【解决方案1】:

    在您的 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();
            }
        }
    }
    

    【讨论】:

    • 这并没有解释核心问题,或者这段代码如何解决它。核心问题是,实例化数学输入控件的线程需要运行一个消息循环才能分派其消息。这是一个重要的细节。
    • @SamHarwell COM 库 micautLib 的位置在哪里?我在VS2017 中尝试了以下内容,但它显示not foundProject--&gt;Add Reference--&gt;COM--&gt;search micautLib。我可能需要浏览到相关的 dll`。请帮忙
    猜你喜欢
    • 1970-01-01
    • 2019-09-23
    • 2017-04-08
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多