How To Marshal Int Arrays Or Pointers To Int Arrays

前端 未结 2 529
礼貌的吻别
礼貌的吻别 2021-01-18 20:59

(I understand this might be duplicate but I don\'t understand the other threads)

I\'m working with C# an I have a third party dll that needs in

2条回答
  •  無奈伤痛
    2021-01-18 21:43

    You could do something like this:

    [DllImport(dllName)]
    static extern void ReadStuff(int id, IntPtr buffer, int length);
    
    
    int[] array = new int[12];
    
    unsafe
    {
      fixed (int* data = &array[0])
        ReadStuff(1, (IntPtr)data, array.Length);
    }
    

    C++ code: (not tested)

    extern "C" __declspec(dllexport) VOID WINAPI ReadStuff(int id, int* buffer, int length);  
    

提交回复
热议问题