您正在定义一个没有 extern "C" 块的 C++ 函数。由于 C++ 允许您重载函数(即创建许多具有不同参数集的 captureCamera() 函数),因此 DLL 中的实际函数名称会有所不同。您可以通过打开 Visual Studio 命令提示符、转到二进制目录并运行以下命令来检查它:
dumpbin /exports YourDll.dll
你会得到这样的东西:
Dump of file debug\dll1.dll
File Type: DLL
Section contains the following exports for dll1.dll
00000000 characteristics
4FE8581B time date stamp Mon Jun 25 14:22:51 2012
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 00011087 ?captureCamera@@YAHAAH@Z = @ILT+130(?captureCamera@@YAHAAH@Z)
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
4000 .text
10000 .textbss
?captureCamera@@YAHAAH@Z是实际编码您指定的参数的错误名称。
如其他答案中所述,只需将 extern "C" 添加到您的声明中:
extern "C" __declspec(dllexport) int captureCamera(int& captureId)
{
...
}
您可以通过重新运行 dumpbin 来重新检查名称是否正确:
Dump of file debug\dll1.dll
File Type: DLL
Section contains the following exports for dll1.dll
00000000 characteristics
4FE858FC time date stamp Mon Jun 25 14:26:36 2012
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 000110B4 captureCamera = @ILT+175(_captureCamera)
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
4000 .text
10000 .textbss