Получить массив структур из нативного dll в c # приложение
У меня есть проект C # .NET 2.0 CF, где мне нужно вызвать метод в родной C ++ DLL. Этот нативный метод возвращает массив типаTableEntry
, Во время вызова нативного метода я не знаю, насколько большим будет массив.
Как я могу получить таблицу из нативной DLL в проект C #? Ниже это эффективно то, что я имею сейчас.
// in C# .NET 2.0 CF project
[StructLayout(LayoutKind.Sequential)]
public struct TableEntry
{
[MarshalAs(UnmanagedType.LPWStr)] public string description;
public int item;
public int another_item;
public IntPtr some_data;
}
[DllImport("MyDll.dll",
CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Auto)]
public static extern bool GetTable(ref TableEntry[] table);
SomeFunction()
{
TableEntry[] table = null;
bool success = GetTable( ref table );
// at this point, the table is empty
}
// In Native C++ DLL
std::vector< TABLE_ENTRY > global_dll_table;
extern "C" __declspec(dllexport) bool GetTable( TABLE_ENTRY* table )
{
table = &global_dll_table.front();
return true;
}
Спасибо, Пол