I am having problems pinning an array to pass to a Native function as a reference.
here is the native code:
Now here is my managed to unmanaged bridge function:Code:typedef HANDLE HDIB int LoadArrayFromFilename(HDIB ahdib[], int nMax, const char* pszFile);
once inside the native DIB_LoadArrayFromFilename, the pointer 'native' is null, and the clr throws an AccessViolationException ("Trying to read or write protected memory").Code:int Toolkit::Dib::LoadArrayFromFilename(array<IntPtr>^% ahdib, int nMax, String^ pzFileName) { pin_ptr<IntPtr> p = &ahdib[0]; HDIB * native = (HDIB*)p->ToPointer(); return ::DIB_LoadArrayFromFilename(native, nMax, (char*)SystemStringToCSTR(pzFileName)); }
Here is example VB code passing an array to be filled out:
So, does anyone know what is wrong with my managed bridge function?Code:Dim pages(100) As IntPtr Toolkit.Dib.LoadArrayFromFilename(pages, 100, szFileName)




Reply With Quote