I am trying to port a C++ library with a C calling convention to C#.
The project is at https://github.com/Esri/lepcc
I am trying to port the sample C++ application and use the .DLL from the Lepcc C++ project.
I am getting an access violation (memory corrupt) when the application ends but the data in the variable ptVec is correct and matches the C++ sample application so I am partly there.
I have tracked down the issue to this C++ function in the sample code which when called causes the access violation.
Код: Выделить всё
vector ptVec(nPts);
errCode = (ErrCode)lepcc_decodeXYZ(ctx, &ptr, (int)(len - pos), &nPts, (double*)(&ptVec[0]));
Код: Выделить всё
lepcc_status lepcc_decodeXYZ(lepcc_ContextHdl _ctx, const unsigned char** ppByte, int bufferSize,
unsigned int* nPtsInOut, double* xyzBuffOut)
Код: Выделить всё
[DllImport(LepccDll, CallingConvention = CallingConvention.Cdecl)]
public static extern lepcc_status lepcc_decodeXYZ(IntPtr ctx, ref IntPtr ppByte, int bufferSize,
ref uint nPtsInOut, double[] xyzBuffOut);
Код: Выделить всё
var slpkBytes = System.IO.File.ReadAllBytes(fnIn);
long slpkLength = new FileInfo(fnIn).Length;
IntPtr ctx = LepccInterop.lepcc_createContext();
GCHandle slpkBytesPinned = GCHandle.Alloc(slpkBytes, GCHandleType.Pinned);
IntPtr ptr = slpkBytesPinned.AddrOfPinnedObject() + pos;
double[] ptVec = new double[(int)nPts * 3];
errCode = (ErrorCode)LepccInterop.lepcc_decodeXYZ(ctx, ref ptr, (int)(slpkLength - pos), ref nPts, ptVec);
slpkBytesPinned.Free();
LepccInterop.lepcc_deleteContext(ctx);
Источник: https://stackoverflow.com/questions/781 ... issues-acc