Manually generate ActiveX wrapper after TLBIMP-ed dlls?

有些话、适合烂在心里 提交于 2019-11-30 18:38:13

问题


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?


回答1:


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:

  1. Register your OCX

    regsvr32 abc.ocx

  2. Generate a strong name key pair for you ocx by running

    sn -k

  3. Run TLBIMP and specify the desired namespace

    tlbimp abc.ocx /primary /keyfile:abc.snk /out:abc.dll /namespace:MyNamespace

  4. 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.



来源:https://stackoverflow.com/questions/446121/manually-generate-activex-wrapper-after-tlbimp-ed-dlls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!