I highly recommend that you create an IDL file to design your COM interfaces .
Given your example in your answer, a pretty minimal IDL file might be like this:
import "oaidl.idl"; [object, uuid(1f6efffc-0ac7-3221-8175-5272a09cea82), dual, oleautomation] interface IStreamFrame : IDispatch { [propget] HRESULT Width([out, retval] long *pWidth); [propget] HRESULT Height([out, retval] long *pHeight); [propget] HRESULT Buffer([out, retval] SAFEARRAY(byte) *pBuffer); }; [uuid(1f6efffc-0ac7-3221-8175-5272a09cea83)] library ContosoStreamFrame { importlib("stdole32.tlb"); interface IStreamFrame; };
Then you use midl.exe to create .h with the interfaces C / C ++, _i.c for the CLSID constants and IID for binding C / C ++, dlldata.c for registering RPC, _p.c with the proxy server and marking material of stub and .tlb, which in the general case is an analyzed representation of the .idl file. This is better described in the documentation .
EDIT: It seems impossible to avoid generating C / C ++ files .
EDIT2: I just found a workaround, use nul as the output file for what you don't want. For example, the following command only generates file.tlb :
midl.exe /header nul /iid nul /proxy nul /dlldata nul file.idl
Note. If your IStreamFrame interface IStreamFrame not intended for use in different processes, add the local attribute to the interface.
In C / C ++, you can use the specific files that were generated, or the #import TLB file. In .NET, you can run tlbimp.exe in the TLB file that generates the .NET assembly.
You can also use tlbexp.exe if your project is .NET-oriented. However, this will require you to know the .NET COM annotations and what they mean in terms of IDL, so I'm not sure if there is any profit when saving one additional source file in another language due to the large amount of noise decorations in your interface and class definitions. Perhaps this is a good option if you want to have full control over the classes and interfaces at the initial level, and you want to make it as simple as possible (read, optimize for ease of use and, possibly, speed) in .NET code.
Finally, you can automate all of this in Visual Studio by creating a project. If you are using the IDL approach, add a custom build step that calls midl.exe and tlbimp.exe , and dependent projects depend on this project for the correct build order. If you are using the .NET approach, add a custom build step that calls tlbexp.exe and makes the dependent C / C ++ projects depend on this project.
EDIT: if you do not need the generated C / C ++ files from midl.exe , you can add del commands to your custom build step for specific output files.
EDIT2: Or use the nul workaround described above.
The general approach used when a type library already exists is to use Visual Studio to import into .NET. But you will need to remember to restore the TLB and import it again if you update your IDL file.