exporting function with parm pointer to char string

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Angel (none)
Date: 03/02/04


Date: Tue, 2 Mar 2004 18:25:24 -0400

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.



Relevant Pages

  • Re: Crystalreport export into TIFF
    ... private IntPtr m_pInstance = IntPtr.Zero; ... private string tiff_path; ... public static extern int MessageBox(int hWnd, String text, String ...
    (microsoft.public.vb.crystal)
  • Re: Pinvoke help
    ... public static extern int StartCamera; ... MouseButtons button, Int32 clicks) ... at System.AppDomain.ExecuteAssembly(String assemblyFile, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pinvoke help
    ... public static extern int StartCamera; ... ; an interface function: ... at System.AppDomain.ExecuteAssembly(String assemblyFile, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: P/Invoked OpenPrinter fails when opening network printer
    ... newly created local port lpt2 on PC_2: ... Then I created local printer on PC_2 on lpt2 and everything works fine. ... >>> public static extern int OpenPrinter(string pPrinterName, ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Pinvoke help
    ... ; an interface function: ... public static extern int StartCamera; ... MouseButtons button, Int32 clicks) ...
    (microsoft.public.dotnet.languages.csharp)