简体   繁体   中英

Declaring COM interface pointer without header file

I am writing an application using C# and WinForms. I have an ActiveX control provided by a third party. I drag the ActiveX control to a form, and get an instance of the class (call it "Widget") that the control implements.

Now I need to pass an interface pointer, IWidget, from C# into legacy C++ code. I plan to put the C++ code in a dll and call it from C# using P/Invoke. The problem is I don't know how to provide the IWidget definition to the C++ code. The original authors of the C++ code had header files (say widget.h), so they could #include widget.h, and declare an IWidget pointer.

I don't have the .h (and can't get it). I only have the ActiveX. So how can I declare an IWidget pointer in my dll?

My only idea so far is to create an IDL file from the ActiveX dll. 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. If you create class with this managed version of interface and [ClassInterface(ClassInterfaceType.AutoDispatch)], it should pass through to ActiveX.

See howto for tlbimp activex-wrap

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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