简体   繁体   English

声明不带头文件的COM接口指针

[英]Declaring COM interface pointer without header file

I am writing an application using C# and WinForms. 我正在使用C#和WinForms编写应用程序。 I have an ActiveX control provided by a third party. 我有第三方提供的ActiveX控件。 I drag the ActiveX control to a form, and get an instance of the class (call it "Widget") that the control implements. 我将ActiveX控件拖到窗体上,并获得该控件实现的类的实例(称为“窗口小部件”)。

Now I need to pass an interface pointer, IWidget, from C# into legacy C++ code. 现在,我需要将接口指针IWidget从C#传递到旧版C ++代码中。 I plan to put the C++ code in a dll and call it from C# using P/Invoke. 我计划将C ++代码放在dll中,并使用P / Invoke从C#调用它。 The problem is I don't know how to provide the IWidget definition to the C++ code. 问题是我不知道如何向C ++代码提供IWidget定义。 The original authors of the C++ code had header files (say widget.h), so they could #include widget.h, and declare an IWidget pointer. C ++代码的原始作者有头文件(例如widget.h),因此他们可以#include widget.h,并声明一个IWidget指针。

I don't have the .h (and can't get it). 我没有.h(并且无法获取)。 I only have the ActiveX. 我只有ActiveX。 So how can I declare an IWidget pointer in my dll? 那么如何在dll中声明IWidget指针?

My only idea so far is to create an IDL file from the ActiveX dll. 到目前为止,我唯一的想法是从ActiveX dll创建IDL文件。 Is that a reasonable approach? 那是一个合理的方法吗?

Thanks, Mark 谢谢马克

You can try import metadata from ActiveX with tlbimp.exe which create managed assembly and IWidget should be there. 您可以尝试使用tlbimp.exe从ActiveX导入元数据,这将创建托管程序集,并且IWidget应该在那里。 If you create class with this managed version of interface and [ClassInterface(ClassInterfaceType.AutoDispatch)], it should pass through to ActiveX. 如果使用此接口的托管版本和[ClassInterface(ClassInterfaceType.AutoDispatch)]创建类,则该类应传递给ActiveX。

See howto for tlbimp activex-wrap 请参阅如何使用Tlbimp ActiveX包装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM