开发者

How to Marshal a void* function return type and parameter in C#?

开发者 https://www.devze.com 2023-03-21 02:18 出处:网络
I have a C function with prototype, void* VoidPointer(void*); Now I need to marshal it in C#(using DllImport). But I do not know how to mention the parameters in C# code.

I have a C function with prototype, void* VoidPointer(void*); Now I need to marshal it in C#(using DllImport). But I do not know how to mention the parameters in C# code.

  • static public extern WHAT_RETURN_TYPE VoidPointer( WHAT_PARAMETER_TYPE );
  • How to make a call with the proper parameters in the C# code (SAMPLE USE)

I am new to C# and need to solve this asap ( 开发者_如何学Cin several attempts have got errors like this cannot convert from 'int' to 'System.IntPtr') Thanks.


c# supports void pointers. Just declare the function as

[DllImport("test.dll")]
public static extern unsafe void* VoidPointer(void* AValue);

public unsafe void Test()
{
    int* a;
    int b = 0;

    a = (int*)VoidPointer(&b);
}

(this only works if the void pointers are referencing integers ofcourse)

0

精彩评论

暂无评论...
验证码 换一张
取 消