我有 Windows Mobile GPS 第三方应用程序。这是 C++ 代码,其中代码包含 GPS 自动启用/禁用功能。
我想制作dll。我也这样做了。当用户点击发票时(C#代码)GPS(C++)必须找到。
这是我的源代码GPS.cpp
extern "C" //No name mangling
__declspec(dllexport)
#include "GPS.h"
#include "stdafx.h"
#include "RF PWR.h"
#include "RF PWRDlg.h"
#include "widioctl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
void CaptureGPS()
{
HANDLE hDrv = CreateFile(TEXT("FNC1:"), GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (0 == DeviceIoControl(hDrv, IOCTL_WID_GPS_ON, NULL, 0, NULL, 0, NULL, NULL))
{
RETAILMSG(1, (L"IOCTL_WID_RFID_ON Failed !! \r\n")); return;
}
CloseHandle(hDrv);
}
&这是GPS.h
class Adder
{
public:
Adder(){;};
~Adder(){;};
void CaptureGPS();
};
这是我的来源:http://pastie.org/3436376
它说无法在 PInvoke RF PWF.dll 中找到入口点 CaptureGPS
请任何人帮我解决这个问题..
问题是什么...
最佳答案
我先解释一下,你写的是什么
extern "C" //No name mangling
__declspec(dllexport)
#include "GPS.h"
预处理后会展开为
extern "C" //No name mangling
__declspec(dllexport)
class Adder
{
public:
Adder(){;};
~Adder(){;};
void CaptureGPS();
};
这意味着,你是:
尝试制作
class Adder
C
风格的结构(虽然不可能,因为class Adder
不是 POD ,extern "C"
直接忽略)尝试导出
class Adder
的变量,如果它在class
定义之后定义,例如:extern "C" //No name mangling __declspec(dllexport) class Adder { public: Adder(){;}; ~Adder(){;}; void CaptureGPS(); } variable;
但是它没有定义任何
变量
,所以__declspec(dllexport)
被忽略了。
请注意,您在 class Adder
中声明了一些方法但未定义它们。没关系,虽然您不尝试使用 class Adder
。另请注意,您的 void CaptureGPS()
与 void Adder::CaptureGPS()
无关,它只是单独的函数。
我想的,你应该做的
看来,您只想导出 void CaptureGPS();
如果是,你应该添加到你的头文件中:
extern "C" __declspec(dllexport) void CaptureGPS();
然后,CaptureGPS()
将被导出,您将能够使用 pinvoke
调用它
关于c# - 找不到 PInvoke DLL - BUG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9410197/