Dear Sir,
I need to implement a Win32 DLL and need call it by C# DllImport in WinCE.
So I create a
Win32 Smart Device Project
and choice
Windows Mobile 5.0 Smartphone SDK
,
and create a dll project with Export symbols option.
Then I add
extern "C"
key word before function declare:
.h
#ifdef WINCE2_EXPORTS
#define WINCE2_API __declspec(dllexport)
#else
#define WINCE2_API extern "C" __declspec(dllimport)
#endif
extern "C" WINCE2_API int __cdecl Add(int A,int B);
.cpp
extern "C" WINCE2_API int __cdecl Add(int A,int B)
{
return A+B;
}
When I use DllImport in C#:
[DllImport("WinCE2.dll", EntryPoint = "Add")]
static extern int Add(int A, int B);
I always got a System.MissingMethodException in WinCE 5.0 emulator and WinCE6.0 Device.
I searched some information on google, found some solution.
First, Add .def in project:
LIBRARY "WinCE2"
EXPORTS
Add DATA
But in CSDN forum some one say __declspec(dllexport) can replace the .def file.
But this solution also got
System.MissingMethodException
.
Then I found a solution on Stack Overflow:
May I need add
__cdecl
key word.
And I created a Win32 DLL Project, I found the project setting will add
__cdecl
in default.
But Win32 Smartphone project is not.
So I try it, but also got
System.MissingMethodException
.
Then I try the same code in Win32 DLL and call by C#, it can work.
So I don't know why wince can't work.
Can anyone share me some expeience?