找不到 PInvoke DLL - BUG?
我有 Windows 移动 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
请任何人帮我解决这个问题..
有什么问题...
I have got Windows mobile GPS third party application.That is C++ code which code contain GPS automatic enabling/disabling facility.
I want to make dll. That also i did. When the user click invoice (C# code) GPS (C++) have to find.
This is my source Code 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);
}
& this is the GPS.h
class Adder
{
public:
Adder(){;};
~Adder(){;};
void CaptureGPS();
};
This is my Source : http://pastie.org/3436376
It say can't find entry point CaptureGPS in PInvoke RF PWF.dll
Please anybody help me out this..
What is the issues...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先让我解释一下,你所写的内容
在预处理后将扩展为
这意味着,你是:
尝试制作
class Adder
C
风格的结构(并且同时这是不可能的,因为class Adder
不是 POD,extern "C"
只是被忽略)尝试导出
class Adder
的变量,如果它在class
定义之后定义,例如:但它没有定义任何
变量
,因此__declspec(dllexport)
被简单地忽略。请注意,您在
class Adder
中声明了一些方法,但未定义它们。没关系,尽管您不尝试使用class Adder
。另请注意,您的void CaptureGPS()
与void Adder::CaptureGPS()
没有任何关系,它只是单独的函数。我认为,你应该做什么
似乎,你只想导出
void CaptureGPS();
如果是,你应该添加到你的头文件中:
比,
CaptureGPS()
将被导出,您将能够使用pinvoke
调用它Let me explain first, what you've written
will expand after preprocessing to
It means, you are:
attempting to make
class Adder
C
-style struct (and while it is not possible due toclass Adder
is not POD,extern "C"
simply ignored)attempting export a variable of
class Adder
, if it would defined afterclass
definition, like:But it is no any
variable
defined, so__declspec(dllexport)
simply ignored.Note, that you declared some methods in
class Adder
but not defined them. It is ok, while you do not try to useclass Adder
. Also note, that yourvoid CaptureGPS()
has nothing withvoid Adder::CaptureGPS()
, it is just separate function.What I think, you should do
It seems, you want just export
void CaptureGPS();
If it is, you should add to your header file:
Than,
CaptureGPS()
will be exported and you will be able to call it withpinvoke
MSDN 有一篇文章介绍了为 P/Invoking 编写 DLL 函数并检查通过 dumpbin 导出的名称。它是专门为 Compact Framework 编写的,因此与您正在做的事情非常相关。
也就是说,为什么要为此创建 DLL?为什么不直接从 C# 应用程序 P/Invoke CreateFile、DeviceIoControl 和 CloseHandle?还有另一篇 MSDN 文章介绍了从托管代码中使用流接口驱动程序紧凑框架也是如此。
MSDN has an article that covers writing DLL function for P/Invoking and checking the exported names via dumpbin. It was written specifically for the Compact Framework, so it's very relevant to what you're doing.
That said, why are you creating a DLL for this anyway? Why not just P/Invoke CreateFile, DeviceIoControl and CloseHandle directly from your C# app? There's another MSDN article that covers using Stream Interface Drivers from managed code in the Compact Framework as well.