找不到 PInvoke DLL - BUG?

发布于 2025-01-08 12:29:18 字数 1143 浏览 0 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

≈。彩虹 2025-01-15 12:29:18

首先让我解释一下,你所写的内容

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" //无名称修改
    __declspec(dll导出) 
    类加法器
    {
        民众:
           加法器(){;};
           〜加法器(){;};
           无效捕获GPS();
    } 多变的;
    

    但它没有定义任何变量,因此__declspec(dllexport)被简单地忽略。

请注意,您在 class Adder 中声明了一些方法,但未定义它们。没关系,尽管您不尝试使用class Adder。另请注意,您的 void CaptureGPS()void Adder::CaptureGPS() 没有任何关系,它只是单独的函数

我认为,你应该做什么

似乎,你只想导出 void CaptureGPS();

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

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

比,CaptureGPS()将被导出,您将能够使用 pinvoke 调用它

Let me explain first, what you've written

extern "C"      //No name mangling
__declspec(dllexport) 
#include "GPS.h"

will expand after preprocessing to

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

It means, you are:

  • 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)

  • 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;
    

    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 use class Adder. Also note, that your void CaptureGPS() has nothing with void 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:

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

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

故人如初 2025-01-15 12:29:18

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文