I am trying to use an exported function from a C++ dll with the below signature, from within my C# program.

extern "C" __declspec(dllexport) BOOL S_USB_Memsize(unsigned char *buffer)

In my C# code , I am declaring the use of this function with:

[DllImport("RSTUSBIF.dll",CallingConvention = CallingConvention.Cdecl)]
        public static extern int S_USB_Memsize(IntPtr buffer);

I then invoke this by using:

IntPtr buffer = Marshal.AllocHGlobal(8);
      m_success = S_USB_Memsize(buffer);

The call to S_USB_Memsize keeps returning with zero success and buffer empty. I know that the dll is ok because it works when called outwith C#. Anyone shed any light on what might be happening here?

Thanks.

Turns out the above works fine - my usb device was causing the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.