2

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 a forum someone 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 why wince can't work. I had copied the dll to wince executable file folder Can anyone share me some expeience?

Cloud Hsu
  • 23
  • 6

2 Answers2

2

You built this using the Smartphone SDK, which is ARM-based. The CE 5.0 emulator emulated x86, so it's not going to be callable there. If your CE 6.0 device is likewise x86-based, it too is going to have the same problem. Try building it using an x86 SDK.

ctacke
  • 66,480
  • 18
  • 94
  • 155
1

Your WinCE2.dll is not copied to WinCE device app executable folder. Try getting the same using FileInfo. I cannot find the file. Check the project settings and add the wince2.dll and set it as a content type and provide copy if newer option.

  • The WinCE2.dll is copied to WinCE device app executable folder. I copied it in my WinCE emulator and WinCE device folder but also got MissingMethodException. If the dll did not exist in flofer, maybe I got an exception like FileIsNotExist? – Cloud Hsu Jul 29 '11 at 14:17
  • And .NET smartphone project can't add reference to project, so I manual copied. – Cloud Hsu Jul 29 '11 at 14:27