简体   繁体   English

在C ++项目中导出DLL

[英]Exporting DLLs in a C++ project

I've encountered a strange behavior in __declspec(dllexport) in my project. 我在项目中的__declspec(dllexport)中遇到了奇怪的行为。 I have a C++ project that uses classes, namespaces, try-catches and more cpp elements. 我有一个使用类,名称空间,try-catches和更多cpp元素的C ++项目。 When exporting any dummy function in this DLL, no other C project will be able to load it with LoadLibrary (Getting error 'module not found'). 在此DLL中导出任何伪函数时,其他C项目都无法使用LoadLibrary加载它(获取错误“未找到模块”)。

Is it possible to load dynamically C++ dlls through C projects? 是否可以通过C项目动态加载C ++ dll? These projects are Windows Mobile projects, but they should behave the same as on regular PC win32. 这些项目是Windows Mobile项目,但是它们的行为应与常规PC win32上的行为相同。

I'm stuck on it and any help will be appreciated. 我坚持下去,任何帮助将不胜感激。

Thank you, Emil. 谢谢你,埃米尔。

LoadLibrary is completely oblivious to the language used to compile a module. LoadLibrary完全忽略了用于编译模块的语言。 If LoadLibrary says it can't find the module, then it's very likely the case that it really can't find it . 如果LoadLibrary表示找不到模块,则很可能确实找不到该模块。 Make sure you've specified the right file name. 确保您指定了正确的文件名。 If you've included a drive and path, make sure they're correct, too. 如果已包含驱动器和路径,请确保它们也正确。 If you haven't included a drive or path, then make sure the file exists somewhere where LoadLibrary can find it. 如果尚未包括驱动器或路径,请确保该文件位于LoadLibrary可以找到它的位置。 The places it searches are listed in Dynamic-Link Library Search Order . 它搜索的位置在“ 动态链接库搜索顺序”中列出。 Also consider whether Windows Vista's directory-virtualization feature might be interfering. 还要考虑Windows Vista的目录虚拟化功能是否会受到干扰。

Once the DLL is loaded, you may have any number of other issues in using the C++ DLL from your C code. 一旦加载了DLL,在使用C代码中的C ++ DLL时,您可能会遇到许多其他问题。 The C++ compiler may have mangled the function names, so you'll need to provide the right names when you call GetProcAddress . C ++编译器可能已经弄乱了函数名称,因此在调用GetProcAddress时需要提供正确的名称。 The C++ code might use a different calling convention from what your C code expects, so you may need to change declarations in the C++ code, the C code, or both. C ++代码使用的调用约定可能与C代码期望的约定不同,因此您可能需要更改C ++代码和/或C代码中的声明。 If the C++ functions expect to receive pointers to classes or other C++-specific types, you'll need to change your C++ code so that its API is compatible with C. If your DLL allocates memory that the host program should free, or vice versa, you'll need to make sure that both modules can use the same memory manager. 如果C ++函数希望接收指向类或其他C ++特定类型的指针,则需要更改C ++代码以使其API与C兼容。如果DLL分配了主机程序应释放的内存,反之亦然,您需要确保两个模块都可以使用相同的内存管理器。

All that is separate from the problem you're reporting, though, which is simply that the OS can't find your file. 不过,所有这些与您要报告的问题是分开的,这仅仅是操作系统无法找到您的文件。 Focus on that first. 首先专注于那个。

I found the problem. 我发现了问题。 It was really a dependency dll problem. 这确实是一个依赖项dll问题。 It was not found in the directory of the loading DLL. 在加载DLL的目录中找不到该文件。 Thank you all. 谢谢你们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM