将dll文件导入另一个IDL文件 [英] Import a dll file into another IDL file

查看:212
本文介绍了将dll文件导入另一个IDL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,用于开发Visual C ++中给定组件的代理COM组件。
如果Comp是原始组件,而Proxy_Comp是代理组件,则Proxy_Comp应该能够具有与原始组件相同的接口。

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.

我认为这应该通过导入只有Comp.dll。
我的一个朋友以前做过这个。但我不能这样做。

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?

推荐答案

我假设你正在谈论 importlib IDL文件。它需要一个类型库,文件扩展名是.tlb。它是一个二进制文件,通过在包含紧凑形式的.idl定义的.idl文件上运行midl.exe生成。

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.

DLL不是类型库。然而,在COM Automation中,通常的惯例是将COM服务器的类型库嵌入到DLL中作为资源。非常方便将服务器代码及其接口定义保持在一起。你可以从Visual Studio轻松地看到这一点,使用文件+打开+文件,并选择DLL。您可以选择c:\windows \system32\shell32.dll作为示例。

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.

资源类型名称始终为TYPELIB,打开节点资源ID,始终为1。你可以双击它来查看内容,不是很有趣,因为它只是一个十六进制转储。

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.

关闭窗口并右键单击1,注意导出上下文菜单选项。这让你写一个文件到磁盘,命名为something.tlb。现在,您将有一个importlib()指令喜欢的.tlb的精确副本。

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.

该.tlb可以反过来重新生成原始的。 idl文件。启动Visual Studio提示。运行oleview.exe,文件+打开Typelib并选择.tlb。将焦点设置为右窗格,键入Ctrl + A,Ctrl + C,并将其粘贴到文本编辑器中。

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.

如果原来的.idl只有100%的保真度,那么你可以使用 import 文件是COM Automation Clean,并且不包含任何cpp_quote。

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

这篇关于将dll文件导入另一个IDL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆