Niente da fare,alla soluzione di MItaly ci ero arrivato anche io.
Il mapping dei tipi così complicati mi sta letteralmente uccidendo.
Ricapitoliamo.
Struttura e funzione Cpp:
codice:
struct RetForManagedCode
{
struct
{
wchar_t Number[200];
wchar_t Ip[17];
wchar_t CPing[5];
int Status;
}TelephoneData[255],NextPhonedata[255];
};
extern "C" __declspec(dllexport) void TrStatus(RetForManagedCode *);
Come ho fatto in C#
codice:
[StructLayout(LayoutKind.Auto, CharSet=CharSet.Unicode)]
public struct PhoneData
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=200)] string Number;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=17)] string Ip;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=5)] string Ping;
[MarshalAs(UnmanagedType.SysInt)] int Status;
};
[StructLayout(LayoutKind.Auto)]
public struct RetForManagedCode
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=255)] public PhoneData[] TelData;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=255)] public PhoneData[] NextPhoneData;
};
[DllImport(("\\My Documents\\TrixDLL.dll"), EntryPoint = "TrStatus", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
public static extern void getTrixData(ref RetForManagedCode ret);
#endregion
Uso la funzione così
codice:
TrixDLL.RetForManagedCode ret = new TrixDLL.RetForManagedCode();
ret.NextPhoneData = new TrixDLL.PhoneData[255];
ret.TelData = new TrixDLL.PhoneData[255];
TrixDLL.getTrixData(ref ret);
Esasperato dal vedere un risultato funzionante, ho trasformato la funzione in modo che abbia in ingresso un void* da modificare al momento e mappandolo con System.IntPtr.ToPointer().
La funzione viene eseguita, ma il puntatore rimane comunque 0.