I am using a third party C library with the following opaque handle:
typedef struct _VendorHandle *VendorHandle;
Here is the vendor's C example of how to load the handle:
VendorHandle handle;
int err;
err = vendorLoadFile(&handle, "something.bin");
I am trying to call this method in C# with PInvoke using the following declaration:
[DllImport("VendorLib.dll")]
static extern int vendorLoadFile(IntPtr handle, string path);
Then I added the following code to use the declaration:
IntPtr handle = new IntPtr();
int code = vendorLoadFile(handle, path);
When I run it I'm getting the following error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I know that the DLL is fine and PInvoke is working because I am executing their vendorVersion() method so it has to be something else I'm doing wrong.