问题描述
我有一个名为 hecom32.dll
的DLL。我想在我的应用程序中使用这个。我收到以下内容:
I have a dll called hecom32.dll
. I want to use this in my application. I acll the following:
#import "hecom32.dll"
我收到以下错误:
enter Error 1 error C1083: Cannot open type library file: 'c:\users\dvargo\documents\visual studio 2010\projects\johnny\johnny\hecom32.dll': Error loading type library/DLL. c:\users\dvargo\documents\visual studio 2010\projects\johnny\johnny\johnny.cpp 6 1 Johnny
显然不能添加它。然而,我不确定它究竟是什么问题。有没有办法我可以分析文件,看看为什么它不能导入。有没有不同的方法来使用dll中的函数?
Obviously it cant add it. I am not sure however to determine what is wrong with it. Is there some way that I can analyze the file to see why it cant be imported. Is there a different way to use the functions in the dll?
我使用的是Visual Studio 2010
I am using Visual Studio 2010
推荐答案
如果hecom32.dll实现了COM服务器并将类型库嵌入资源,这将只能正常工作。您可以使用File + Open + File检查,选择dll。您将看到列出的资源,如果您打开节点,应该有一个标有TYPELIB的资源ID为1。
This will only work properly if hecom32.dll implements a COM server and has the type library embedded as a resource. You can check that with File + Open + File, select the dll. You'll see the resources listed, there should be one labeled "TYPELIB" with a resource ID of 1 if you open the node.
当然没有,错误信息说了多少嵌入类型库是一个惯例,它不是必需的。只要保持分开,因为.tlb文件也是可能的。当然,它可能根本不是一个COM服务器。您可以通过在dll上运行Dumpbin.exe / exports来看到。一个COM服务器至少有一个名为DllGetClassObject的导出。
Surely that's missing, the error message says as much. Embedding a type library is a convention, it isn't required. Just keeping it separate as a .tlb file is possible as well. And of course, it might not be a COM server at all. You can see that by running Dumpbin.exe /exports on the dll. A COM server has at least an export named "DllGetClassObject".
如果没有一个可以,那么最好联系DLL的所有者,并请求帮助如何正确使用它。通常需要一个带有导出函数和.lib文件的声明的.h文件,以便您可以链接。
If none of this pans out then you'd better contact the owner of the DLL and ask for help on how to use it properly. Which typically requires having a .h file with the declarations of the exported functions and a .lib file so you can link it.
这篇关于不能在C ++应用程序中导入dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!