none
C++ DLL in C# WinMobile 6.1 Project - 1c2 machine (Thumb) vs 14c machine (x86) RRS feed

  • Question

  • I am trying to import a few DLLs that have been compiled for 1c2 machine (thumb) into a WinMobile 6.1 C# Smart Device project.

    However when i try to import them to my C# project I get "A reference to ... cannot be added", I can add DLLs that have been compiled for 14C machine (x86), my C# WinMobile project has Any CPU as it's setting, is it possible to import 1C2 machine DLLs or do I need these to be recompiled to 14C machine x86?

    The project is to RUN on a Psion Teklogix 7505 - CPU PXA270M (ARM)
    Monday, November 26, 2012 1:19 PM

Answers

  • You can add a reference to a native DLL only for this specific case:

    1. DLL is a COM DLL (pretty common).

    2. DLL has embedded IDL (rare).

    3. DLL can run on your dev machine (i.e. compiled for x86).

    Assuming #1 and #2 are met then it is not possible because of #3. 

    However since you have a version of the same DLL for which all 3 conditions are met you can add a reference to x86 version (assuming they both have the same IDL). That is possible since adding reference to a native DLL does not use the DLL itself but creates interop library for it. Then reference to that interop library is actually added. Even though interop library is generated for the desktop framework it may just work on device due to automatic retargeting of System DLL types. Since IDL is the same then at runtime proper ARM DLL would be loaded and used. There may be issues with marshaling since NETCF has number of limitations on that.

    A more robust approach would be to decompile created interop library (e.g. using ILSpy) and then create new device DLL project. Then you have a proper interop DLL and you can fix marshaling if needed.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, November 26, 2012 5:01 PM
    Moderator