找不到 PInvoke DLL - BUG?

找不到 PInvoke DLL - BUG?

问题描述:

我有 Windows 移动 GPS 第三方应用程序.那是 C++ 代码,其中包含 GPS 自动启用/禁用功能.

I have got Windows mobile GPS third party application.That is C++ code which code contain GPS automatic enabling/disabling facility.

我想制作dll.我也是这样做的.当用户点击发票(C#代码)GPS(C++)时有找到.

I want to make dll. That also i did. When the user click invoice (C# code) GPS (C++) have to find.

这是我的源代码 GPS.cpp

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);
}

&这是 GPS.h

& this is the GPS.h

class Adder
 {
    public:
       Adder(){;};
       ~Adder(){;};
       void CaptureGPS();
 };

这是我的来源:http://pastie.org/3436376

它说在PInvoke RF PWF.dll中找不到入口点CaptureGPS

请任何人帮我解决这个..

Please anybody help me out this..

有什么问题...

我先解释一下,你写了什么

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" 直接忽略)

  • attempting to make class Adder C-style struct (and while it is not possible due to class Adder is not POD, extern "C" simply ignored)

试图导出一个class Adder的变量,如果它会在class定义之后定义,比如:

attempting export a variable of class Adder, if it would defined after class definition, like:

extern "C"      //No name mangling
__declspec(dllexport) 
class Adder
{
    public:
       Adder(){;};
       ~Adder(){;};
       void CaptureGPS();
} variable;

但是它没有定义任何变量,所以__declspec(dllexport)被忽略了.

But it is no any variable defined, so __declspec(dllexport) simply ignored.

请注意,您在 class Adder 中声明了一些方法,但没有定义它们.没关系,虽然您不要尝试使用 class Adder.另请注意,您的 void CaptureGPS()void Adder::CaptureGPS() 没有任何关系,它只是单独的功能.

Note, that you declared some methods in class Adder but not defined them. It is ok, while you do not try to use class Adder. Also note, that your void CaptureGPS() has nothing with void Adder::CaptureGPS(), it is just separate function.

看来,您只想导出 void CaptureGPS();

如果是,你应该添加到你的头文件中:

If it is, you should add to your header file:

extern "C" __declspec(dllexport) void CaptureGPS();

然后,CaptureGPS() 将被导出,您将能够使用 pinvoke

Than, CaptureGPS() will be exported and you will be able to call it with pinvoke