locked
MissingMethodException problem using PInvoke RRS feed

  • Question

  • Hello Everyone,

    I'm having problems trying to access a library developed in C++ from a .Net CF program. I've decide to simplify the problem as much as possible, but the problem already persists.

    I have the following DLL.

    /*************TESTDLLPROJECT.h

    #ifdef TESTDLLPROJECT_EXPORTS
    #define TESTDLLPROJECT_API __declspec(dllexport)
    #else
    #define TESTDLLPROJECT_API __declspec(dllimport)
    #endif

    extern "C" TESTDLLPROJECT_API int fnTestDllProject(void);

    /******************MYDLL.C

    #include "TestDllProject.h"
    #include <windows.h>

    // This is an example of an exported variable
    //extern "C" TESTDLLPROJECT_API int nTestDllProject=0;

    // This is an example of an exported function.
    extern "C" TESTDLLPROJECT_API int fnTestDllProject(void)
    {
     return 42;
    }

    /*****************

    As you can see it's the simplest DLL exporting a function.

    Dumpbin shows the following output:

    File Type: DLL

      Section contains the following exports for TestDllProject.dll

        00000000 characteristics
        4AA54C9A time date stamp Mon Sep 07 20:10:34 2009
            0.00 version
               1 ordinal base
               1 number of functions
               1 number of names

        ordinal hint RVA      name

              1    0 00001000 fnTestDllProject

      Summary

            1000 .data
            1000 .pdata
            1000 .rdata
            1000 .reloc
            1000 .text

    The DLL has no dependency (shown with dumpbin /dependents).

    In C# I use the following definition to access this function:

    [DllImport("TestDllProject.dll", EntryPoint = "1")]
            static extern Int32 fnTestDllProject();

    I'm deploying the DLL and the application in the same folder of a Windows CE 5.0 device.
    I'm not able to install the SDK of the device correctly so I've used the Windows Mobile's SDK to build the DLL and the application.

    Any help will be appreciated
    .

    Best regards,
    xmp.

     

    Monday, September 7, 2009 6:31 PM

Answers

  • Hi,

    Thanks for your advice.

    I've tried removing the void but the problem still persists. The Entry Point set to the ordinal was one of the tests, earlier I tried to run with the method name but the result was the same.

    Please let me know any possible advice,

    Thanks,
    xmp.


    • Marked as answer by xmp Tuesday, September 8, 2009 1:03 PM
    Tuesday, September 8, 2009 7:31 AM

All replies

  • Hi,

    Should you have a void in your native method's definition? Shouldn't it just have an empty parameter list?

    Do you need an ordinal entry point? Can you not just call the method by name?

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Monday, September 7, 2009 6:44 PM
  • Hi,

    Thanks for your advice.

    I've tried removing the void but the problem still persists. The Entry Point set to the ordinal was one of the tests, earlier I tried to run with the method name but the result was the same.

    Please let me know any possible advice,

    Thanks,
    xmp.


    • Marked as answer by xmp Tuesday, September 8, 2009 1:03 PM
    Tuesday, September 8, 2009 7:31 AM
  • Hi All,

    The problem has been solved reinstalling the SDK of the target device (problems between Windows Vista and Visual Studio) and recompiling the library and the program.

    Everything worked without changing a source code.

    Hope this is helpful for someone else.

    Thanks everyone,
    xmp.

    Tuesday, September 8, 2009 1:03 PM