An managed/unmanaged code interop experience with Windows Mobile


I wanted to write my GUI using C#/.NET WinForms as it is a lot easier than MFC and more portable. But I needed to access some low-level functions packaged in MFC dll. So I needed  to call unmanaged code and I found 2 usefull articles:

Call Unmanaged Code. Part 1 – Simple DLLImport

Call Unmanaged Code Part 2 – Marshal Class

I tried the technique on PC. It works. When I tried it on Windows Mobile 6, it kept showing “Can’t find PInvoke DLL ‘nameofmydll.dll’.” I put both managed & unmanaged dll in the same folder. The message didn’t make any sense. I searched on internet, some people were saying the my MFC dll must be compiled for the right platform. I checked my target platform (under Configuration Properties\C/C++\Advanced\Compile For Architecture) and it was correct ARM4. It baffled me. Eventually, I tried to link to static MFC dll, and it works.

My theory was that MS didn’t include MFC dll (at least the version I need) with my Windows Mobile. Later, I found out from MS: “MFC8.0 (DLL) is not ensured to be on the device. ” Link to the article.

Advertisements
An managed/unmanaged code interop experience with Windows Mobile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s