I have several ActiveX components that needed to be accessed from a C# project.
I can import them via Visual Studio's add reference dialog, which will also automatically generate wrappers class. (i.e. ABCLib
and AxABCLib
)
I know that I can generate the primary interop assembly manually by running TLBIMP /primary
on each individual OCX file but I could not find a way to generate the ActiveX wrapper unless I do it via Visual Studio user interface.
Is there a command-line version that generate the ActiveX wrapper in the .NET SDK?
I want to generate the AxABCLib
version from the PIA I got from TLBIMP manually. (i.e. setting namespaces, output dll filenames etc.) Is it possible?
Oh... found it after looking at the folder where TLBIMP belongs.
It's called
AxImp
.C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\AxImp.exe
So basically, to generate a PIA DLL in your own customized namespace:
Register your OCX
regsvr32 abc.ocx
Generate a strong name key pair for you ocx by running
sn -k
Run TLBIMP and specify the desired namespace
tlbimp abc.ocx /primary /keyfile:abc.snk /out:abc.dll /namespace:MyNamespace
Run AXIMP on the ocx and use the
rcw
switch to use your own manully generated PIA DLL.aximp abc.ocx /source /rcw:abc.dll
That should do it.
There are however some problems with ancient TLBs being imported. I am not sure how to fix that yet.