问题
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...
回答1:
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 toclass Adder
is not POD,extern "C"
simply ignored)attempting export a variable of
class Adder
, if it would defined afterclass
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
回答2:
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.
来源:https://stackoverflow.com/questions/9410197/cant-find-pinvoke-dll-bug