Проблемы с попыткой портировать LEPCC с GitHub на C# — проблемы с DllImport/нарушение прав доступаC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Гость
 Проблемы с попыткой портировать LEPCC с GitHub на C# — проблемы с DllImport/нарушение прав доступа

Сообщение Гость »


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]));
The C++ method declaration looks like this

Код: Выделить всё

lepcc_status lepcc_decodeXYZ(lepcc_ContextHdl _ctx, const unsigned char** ppByte, int bufferSize,
unsigned int* nPtsInOut, double* xyzBuffOut)
In C# I have translated the call to the following (may or may not be correct)

Код: Выделить всё

[DllImport(LepccDll, CallingConvention = CallingConvention.Cdecl)]
public static extern lepcc_status lepcc_decodeXYZ(IntPtr ctx, ref IntPtr ppByte, int bufferSize,
ref uint nPtsInOut, double[] xyzBuffOut);
and my C# calling implementation

Код: Выделить всё

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);
Does my DllImport look correct? I am out of my depth here.


Источник: https://stackoverflow.com/questions/781 ... issues-acc
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»