Import a dll file into another IDL file

久未见 提交于 2019-12-08 07:48:59

问题


I am working on a project for developing a proxy COM component for the given component in visual C++. If "Comp" is the original component and Proxy_Comp is the proxy component, then Proxy_Comp should be capable of having the same Interfaces as of the original component.

I think this should be done by importing only the "Comp.dll". One of my friends has done this successfully before. But I cannot do it. Could anyone please help?


回答1:


I'll assume you are talking about the importlib directive in the IDL file. It requires a type library, the filename extension is .tlb. It is a binary file produced by running midl.exe on an .idl file that contains the .idl definitions in a compact form.

A DLL is not a type library. It is a common convention however in COM Automation to embed the type library for the COM server as a resource inside the DLL. Quite handy to keep the server code and its interface definitions together. You can see this easily from Visual Studio, use File + Open + File and select the DLL. You could pick c:\windows\system32\shell32.dll as an example.

The resource type name is invariably "TYPELIB", open the node to see the resource ID, invariably "1". You can double click it to look at the content, not very interesting since it is only a hex dump. You'll recognize the strings though, the names of the interfaces, coclasses and their members.

Close that window and right-click the "1", note the Export context menu option. That lets you write a file to disk, name it something.tlb. You'll now have an exact copy of the .tlb that the importlib() directive likes.

That .tlb can be decompiled in turn to re-generated the original .idl file. Start the Visual Studio prompt. Run oleview.exe, File + Open Typelib and select the .tlb. Set the focus to the right pane, type Ctrl+A, Ctrl+C and paste that into a text editor. Now you got the original .idl back, you could just use the import directive.

This only has 100% fidelity if the original .idl file was COM Automation clean and didn't contain any cpp_quote.




回答2:


You want the interface definitions from the type library (.tlb data embedded in the DLL). If you have the Windows SDK utilities installed (probably with VS) then run OLE/COM Object Viewer and "File", "View Typelib" for your DLL. That should give you an IDL dump that you can copy the interface definitions out of.

(There may also be a way to import the .tlb data at IDL compile time if that's what you're after, but I'm not sure sorry.)



来源:https://stackoverflow.com/questions/8720309/import-a-dll-file-into-another-idl-file

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