简体   繁体   English

将C ++ DLL导入C#智能设备应用程序

[英]Importing C++ DLL into C# Smart Device Application

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. 我将C ++ Win32 DLL导入C#Windows应用程序没有问题。 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. 但是我想做的是将C ++ DLL导入C#“智能设备应用程序”,尤其是使用Visual Studio 2005。

In my (TestDLL.dll) C++ DLL source file I have the following lines: 在我的(TestDLL.dll)C ++ DLL源文件中,有以下几行:

#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: 我的C#包装器(Wrapper.cs)类具有以下内容:

[DllImport(TestDLL.dll)]
private static extern void foo();

public static void fooCS()
{
    foo();
}

And my C# driver class is calling the following: 我的C#驱动程序类正在调用以下代码:

Wrapper.fooCS();

And I connected my Pocket PC 2003 device to PC, then I started debugging and ran the program. 然后将Pocket PC 2003设备连接到PC,然后开始调试并运行该程序。 And I get the following error message: 我收到以下错误消息:

MissingMethodException: PInvoke DLL 'TestDLL.dll' cannot be found. MissingMethodException:找不到PInvoke DLL'TestDLL.dll'。

I double triple checked my DLL location, so it cannot be the problem. 我对我的DLL位置进行了三重检查,所以这不可能是问题。 And then I tried using many different templates from Visual Studio 2005. 然后,我尝试使用Visual Studio 2005中的许多不同模板。

  • MFC Smart Device DLL MFC智能设备DLL
  • MFC Smart Device MFC智能设备
  • Application Win32 Smart Device 应用程序Win32智能设备
  • Project ATL Smart Device Project 项目ATL智能设备项目
  • Win32 DLL Win32 DLL

But nothing seemed to work. 但是似乎没有任何效果。 Always the same runtime error. 总是相同的运行时错误。

I also tried to changing CPU configuration when building the solution. 构建解决方案时,我还尝试更改CPU配置。 But no help. 但是没有帮助。

So I am now seeking for experts' helps. 因此,我现在正在寻求专家的帮助。

FYI, my device has the following platform: 仅供参考,我的设备具有以下平台:

  • Windows Mobile 6 Classic Windows Mobile 6经典版
  • CE OS 5.2.1433 CE OS 5.2.1433
  • Processor: ARM920T 处理器:ARM920T

And the development environment is... 开发环境是...

  • Windows 7 64bits Windows 7 64位
  • Visual Studio 2005 Visual Studio 2005

Thank you in advance, 先感谢您,

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. 应用程序无法加载DLL文件的原因是因为我正在移动设备上运行调试。 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. 因此,我手动将DLL文件和应用程序的EXE文件复制到了移动设备并运行了该程序。 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. 我目前所知道的唯一方法是手动将DLL和EXE文件的发行版本复制到移动设备上并进行测试。 =( =(

Does anybody know the better way? 有人知道更好的方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM