如何创建Win32 SmartPone dll并通过C#DllImport调用 [英] How to create win32 smartpone dll and call by C# DllImport

查看:69
本文介绍了如何创建Win32 SmartPone dll并通过C#DllImport调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,
我需要实现Win32 DLL,并需要通过WinCE中的C#DllImport调用它.
所以我创建一个Win32 Smart Device Project并选择Windows Mobile 5.0 Smartphone SDK
并使用导出符号"选项创建一个dll项目.
然后在函数声明之前添加extern "C"关键字:

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



当我在C#中使用DllImport时:



When I use DllImport in C#:

[DllImport("WinCE2.dll", EntryPoint = "Add")]
static extern int Add(int A, int B);


我在WinCE 5.0仿真器和WinCE6.0设备中总是得到System.MissingMethodException.

我在Google上搜索了一些信息,找到了一些解决方案.
首先,在项目中添加.def:


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 


但是在CSDN论坛中,有人说__declspec(dllexport)可以替换.def文件.
但是此解决方案也得到了System.MissingMethodException.

然后我找到了关于堆栈溢出的解决方案:
我是否需要添加__cdecl关键字.
我创建了一个Win32 DLL项目,发现该项目设置将默认添加__cdecl.
但是Win32 Smartphone项目不是.
所以我尝试了,但也得到了System.MissingMethodException.
然后,我尝试在Win32 DLL中使用相同的代码并通过C#调用,它可以正常工作.
所以我不知道为什么wince无法工作.
谁能分享给我一些经验?


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?

推荐答案

我尝试在计算机上安装WinCE Standard SDK 5.0并创建一个标准的sdk项目.
然后,我选择x86 CPU来构建dll,并且该dll可以正常工作.
I try to install WinCE Standard SDK 5.0 in my computer and create a standard sdk project.
Then I select x86 CPU to build dll, and the dll can work.


这篇关于如何创建Win32 SmartPone dll并通过C#DllImport调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆