P/Invoking function via a mangled name

前端 未结 1 1035
一生所求
一生所求 2020-12-20 01:11

I\'m trying to call an function in an unmanaged c++ dll in .net cf 3.5 in a windows ce 6.0 environment.

The struct is defined as:

typedef struct TagO         


        
相关标签:
1条回答
  • 2020-12-20 02:13

    You can only call functions that have been exported as C style functions. As far as I am aware you cannot call straight C++ functions via P/Invoke, e.g.:

    How to set up a C++ function so that it can be used by p/invoke?

    Update

    Actually, it does appear you can use mangled names when calling a function via P/Invoke. This is something I could never get working in the past, so I stand corrected. Using names rather than ordinals should be more resilient too:

    Reference: Entry Point Not Found Exception

    So something like:

    [DllImport(gsmaAdapterDLLName,
        EntryPoint="?GetCurOperatorInfo@CGSMAdapter@@YAHPAUTagOperatorInfo@@@Z", 
        ExactSpelling = true,
        CallingConvention = CallingConvention.Cdecl)]
    public static extern bool GetCurOperatorInfo(out TagOperatorInfo info);
    

    And for .Net CF:

    DllImport(gsmaAdapterDLLName,
        EntryPoint="?GetCurOperatorInfo@CGSMAdapter@@YAHPAUTagOperatorInfo@@@Z", 
        CallingConvention = CallingConvention.WinApi)]
    public static extern bool GetCurOperatorInfo(out TagOperatorInfo info);
    
    0 讨论(0)
提交回复
热议问题