【问题标题】:How to trigger code from an exposed COM Interface's method?如何从暴露的 COM 接口的方法中触发代码?
【发布时间】:2015-04-23 09:00:42
【问题描述】:

我公司使用的软件允许创建插件,但插件必须是 COM 对象并实现如下所示的 IProfilePlugIn 接口:

namespace profile
{
    [Guid("CE694B21-9547-11D3-8606-BB9193E3F22C")]
    [TypeLibType(192)]
    public interface IProfilePlugIn
    {
        [DispId(9)]
        void AppClose();
        [DispId(8)]
        void AppCloseQuery(ref bool CanClose);
        [DispId(10)]
        void AppIdle();
        [DispId(11)]
        void AppOpen(ref bool ShowQuickStart, ref bool Continue);
        [DispId(3)]
        void ClientNotification(IProfileClient ProFileClient, string FileName, string ClientID, int Action, ref int Response);
        [DispId(7)]
        void ExecuteAction(string AActionID, ref bool Handled);
        [DispId(2)]
        void FieldChangeNotification(IProfileClient ProFileClient, int UniqueID);
        [DispId(4)]
        int GetAboutBoxBitmap();
        [DispId(15)]
        void GetEncryptionType(ref int EncryptionType);
        [DispId(14)]
        void GetLicenseCode(ref string LicenseCode);
        [DispId(13)]
        void GetLicenseName(ref string LicenseName);
        [DispId(6)]
        IProfileDialog GetProfileDialog();
        [DispId(5)]
        int GetSplashBitmap();
        [DispId(1)]
        void Initialize();
        [DispId(12)]
        bool RTUNotification(IProfileClient ProFileClient, int RTUType, out string AError);
    }
}

有一个方法 AppOpen(ref bool ShowQuickStart, ref bool Continue);在程序第一次打开时执行。例如,如何在该方法期间弹出一个打开的消息框,而无需实现所有其他方法?

据我所知,我必须在 VS 中创建一个 ClassLibrary,然后将其标记为 ComVisible 并从接口继承并添加 GUID 属性和 ClassInterfaceType,但这就是我迷路的地方。

我知道一旦创建,我必须注册 COM 对象并执行一些注册表更改,以便程序使用插件。

我需要做什么才能制作 MessageBox.Show("Test");在 AppOpen 方法期间执行?

【问题讨论】:

    标签: c# plugins com


    【解决方案1】:

    我需要做什么才能制作 MessageBox.Show("Test");在 AppOpen 方法期间执行?

    void AppOpen(ref bool ShowQuickStart, ref bool Continue)
    {
        MessageBox.Show ("Test");
    }
    

    【讨论】:

    • 所以实际上只需要从该接口继承并声明我自己的方法?对于我没有实现的方法,我需要做的只是添加没有正文的方法?
    • 1) 是的。 2)这取决于 - 你需要参考他们的文档。我看到的一些方法有ref 参数,这表明插件主机系统会期待你的东西?再一次,这可能适用于任何方法
    • 好吧,我很抱歉我的术语太糟糕了,我对此很陌生,但我的工作让我弄清楚了这一点。因为我正在使用接口,所以我必须实现所有方法,但本质上只是让主体为空?感谢您的帮助。
    • 是的,没错 - 就 .NET 而言,您至少必须为 void 方法提供一个空主体。但是,返回 bool 的方法必须返回一些东西。这是您需要做的最少的事情。同样,请参阅插件文档以了解哪些方法真正需要做某事。祝我的朋友好运
    • 他们基本上没有文档或示例,它只是告诉我需要在 COM 对象中实现接口 IProfilePlugin,然后告诉我如何让程序使用插件。不幸的是,他们雇不起专业人士。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-21
    • 2010-12-24
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多