如何在WinCE中通过C# DllImport创建win32 smartpone dll并调用

发布于 2024-11-27 01:31:37 字数 1201 浏览 10 评论 0原文

我需要实现一个Win32 DLL,并需要在WinCE 中通过C# DllImport 调用它。 所以我创建了一个Win32智能设备项目并选择Windows Mobile 5.0 Smartphone SDK, 并使用导出符号选项创建一个 dll 项目。 然后我在函数声明之前添加 extern "C" 关键字:

.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 时:

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

我总是在 WinCE 5.0 模拟器和 WinCE6.0 设备中遇到 System.MissingMethodException

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

LIBRARY     "WinCE2"
EXPORTS
Add         DATA 

但是在论坛上有人说__declspec(dllexport)可以替换.def文件。 但这个解决方案也遇到了System.MissingMethodException。

然后我在Stack Overflow上找到了解决方案: 我需要添加 __cdecl 关键字吗? 我创建了一个Win32 DLL项目,我发现项目设置默认会添加__cdecl。 但 Win32 智能手机项目不是。 所以我尝试了一下,但也得到了System.MissingMethodException。 然后我在Win32 DLL中尝试相同的代码并通过C#调用,它可以工作。 所以我不明白为什么wince不能工作。 我已经将dll复制到wince可执行文件夹中 有人可以分享一些经验给我吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

℡寂寞咖啡 2024-12-04 01:31:37

您使用基于 ARM 的智能手机 SDK 构建了它。 CE 5.0 模拟器模拟 x86,因此无法在那里调用。如果您的 CE 6.0 设备同样基于 x86,它也会遇到同样的问题。尝试使用 x86 SDK 构建它。

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.

回首观望 2024-12-04 01:31:37

您的 WinCE2.dll 未复制到 WinCE 设备应用程序可执行文件夹。尝试使用 FileInfo 获得相同的结果。我找不到该文件。检查项目设置并添加 wince2.dll 并将其设置为内容类型并提供“如果较新则复制”选项。

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.

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