导入 C++ DLL 到 C# 智能设备应用程序中
在我查阅了大量博客和网页并尝试了人们解释的几乎所有内容之后,我问了这个问题。
我将 C++ Win32 DLL 导入 C# Windows 应用程序没有问题。它实际上是直截了当的。
但我想做的是将 C++ DLL 导入 C#“智能设备应用程序”,特别是使用 Visual Studio 2005。
在我的 (TestDLL.dll) C++ DLL 源文件中,我有以下几行:
#if defined (__cplusplus)
extern "C" {
#endif
__declspec(dllexport) void __cdecl foo();
#if defined (__cplusplus)
};
#endif
extern void __cdecl foo()
{
}
和我的 C# 包装器 (Wrapper.cs) ) 类具有以下内容:
[DllImport(TestDLL.dll)]
private static extern void foo();
public static void fooCS()
{
foo();
}
我的 C# 驱动程序类正在调用以下内容:
Wrapper.fooCS();
我将 Pocket PC 2003 设备连接到 PC,然后开始调试并运行该程序。我收到以下错误消息:
MissingMethodException:PInvoke DLL 找不到“TestDLL.dll”。
我仔细检查了我的 DLL 位置,所以这不可能是问题所在。然后我尝试使用 Visual Studio 2005 中的许多不同模板。
- MFC 智能设备 DLL
- MFC 智能设备
- 应用程序 Win32 智能设备
- 项目 ATL 智能设备项目
- Win32 DLL
但似乎没有任何效果。始终出现相同的运行时错误。
我还尝试在构建解决方案时更改 CPU 配置。但没有帮助。
所以我现在寻求专家的帮助。
仅供参考,我的设备具有以下平台:
- Windows Mobile 6 Classic
- CE OS 5.2.1433
- 处理器:ARM920T
开发环境是...
- Windows 7 64位
- Visual Studio 2005
提前谢谢您,
I am asking this question after I looked up tons of blogs and webpages and tried almost everything people explained.
I have no problem with importing C++ Win32 DLL into C# Windows Application. And it was actually straight forward.
But what I am trying to do is importing C++ DLL into C# "Smart Device Application," especially using Visual Studio 2005.
In my (TestDLL.dll) C++ DLL source file I have the following lines:
#if defined (__cplusplus)
extern "C" {
#endif
__declspec(dllexport) void __cdecl foo();
#if defined (__cplusplus)
};
#endif
extern void __cdecl foo()
{
}
And my C# wrapper (Wrapper.cs) class has the following:
[DllImport(TestDLL.dll)]
private static extern void foo();
public static void fooCS()
{
foo();
}
And my C# driver class is calling the following:
Wrapper.fooCS();
And I connected my Pocket PC 2003 device to PC, then I started debugging and ran the program. And I get the following error message:
MissingMethodException: PInvoke DLL
'TestDLL.dll' cannot be found.
I double triple checked my DLL location, so it cannot be the problem. And then I tried using many different templates from Visual Studio 2005.
- MFC Smart Device DLL
- MFC Smart Device
- Application Win32 Smart Device
- Project ATL Smart Device Project
- Win32 DLL
But nothing seemed to work. Always the same runtime error.
I also tried to changing CPU configuration when building the solution. But no help.
So I am now seeking for experts' helps.
FYI, my device has the following platform:
- Windows Mobile 6 Classic
- CE OS 5.2.1433
- Processor: ARM920T
And the development environment is...
- Windows 7 64bits
- Visual Studio 2005
Thank you in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对不起,我真的很蠢。
应用程序无法加载DLL文件的原因是因为我在移动设备上运行调试。这导致了路径问题。
所以我手动将DLL文件和应用程序的EXE文件复制到移动设备并运行程序。它工作得很好。
汉斯(评论者),你是对的。谢谢。 =)
现在,我的问题变成了如何轻松调试这个问题。
我目前知道的唯一方法是手动将 DLL 和 EXE 文件的发行版本复制到移动设备并进行测试。 =(
有人知道更好的方法吗?
Sorry, I was being really stupid.
The reason why the application could not load the DLL file was because I was running debug on a mobile device. And it caused a path problem.
So I manually copied the DLL file and application's EXE file to the mobile device and ran the program. It worked perfectly fine.
Hans (commenter), you were right. Thanks. =)
Now, my question would now become how I could easily debug this problem.
The only way I currently know is manually copying the release version of DLL and EXE files to the mobile device and testing it. =(
Does anybody know the better way?