0
votes

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 ( in several attempts have got errors like this cannot convert from 'int' to 'System.IntPtr') Thanks.

1
i thought c# supported voidpointers (just use void*)hcb
IntPtr is the managed version of void*leppie
It is an absolutely hopeless function signature. If you don't know anything about what the argument and return value are supposed to represent then IntPtr is the only choice. You'll have to deal with the consequences. One of which is that there's little point in trying.Hans Passant

1 Answers

2
votes

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)