Rufen Sie eine Reihe von Strukturen von der nativen DLL zur C # -Anwendung ab
Ich habe ein C # .NET 2.0 CF-Projekt, in dem ich eine Methode in einer systemeigenen C ++ - DLL aufrufen muss. Diese native Methode gibt ein Array vom Typ zurückTableEntry
. Zum Zeitpunkt des Aufrufs der nativen Methode ist nicht bekannt, wie groß das Array sein wird.
Wie kann ich die Tabelle von der nativen DLL in das C # -Projekt übertragen? Unten ist effektiv was ich jetzt habe.
// 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;
}
Danke, PaulH