开发者

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. 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开发者_C百科 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,


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜