Я создаю управляемую C ++ / CLI DLL, которая оборачивает и делает доступной одну функцию, находящуюся в статической библиотеке c ++.
Большая часть ее работала, за исключением одной постоянной проблемы.
Вот как эта функция выглядит в .h файле моей неуправляемой библиотеки.
typedef struct
{
float a;
float b;
}MyStruct;
bool GetData(float p1, float* p2, MyStruct buffer[]);
и вот что у меня есть в оболочке C ++ / CLI:
H файл:
using namespace System::Runtime::InteropServices
public ref struct MyManagedStruct
{
float a;
float b;
}
public ref class Wrapper
{
bool static GetDataManaged(
float p1, [Out] float %p2,
array<MyManagedStruct^> ^ managedBuffer);
}
Файл CPP:
bool Wrapper::GetDataManaged(
float p1, [Out] float %p2,
array<MyManagedStruct^> ^ managedBuffer)
{
float f;
//managed buffer is assumed allocated by the .net caller
MyStruct* unmanagedBuffer = new MyStruct[managedBuffer->Length];
bool retval = GetData(p1, &f, unmanagedBuffer);
/* this doesn't work... any better suggestions?
for (int i=0;i<n;i++)
BallDatabuffer[i] = buffer[i];
*/
p2 = f;
return retval;
}
Любая помощь приветствуется.