1

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

1 Answers1

0

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

Community
  • 1
  • 1
Radik
  • 2,715
  • 1
  • 19
  • 24