exporting function with parm pointer to char string

  • Thread starter Thread starter Angel
  • Start date Start date
A

Angel

I'm exporting a C-style function call with this syntax:

int getDate(char *date);

I'm trying to export to my c# app like this:

[DllImport("C:\\zm7\\Developm\\DLL\\W32.DLL")]
public static extern int getDate(System.IntPtr ptr);
public void getDate()
{
IntPtr ptr = new IntPtr();
string str = "";
getDate(ptr); //// ERROR: Object reference not set to an instance of
an object
str = Marshal.PtrToStringAnsi(ptr);
}

What Am I doing wrong?

Thanks.
 
What Am I doing wrong?

You're passing in a null pointer. Try it this instead

public static extern int getDate(StringBuilder ptr);



Mattias
 
That worked.

Thank you.

Mattias Sjögren said:
You're passing in a null pointer. Try it this instead

public static extern int getDate(StringBuilder ptr);



Mattias
 
Back
Top