1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
internal class CS_StructReportEntity
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32 + 1)]
public string NameType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256 + 1)]
public string Name;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
internal class CS_StructReport
{
public int iRank;
public string pData;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256 + 1)]
public string ListName;
public int iEntityId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024 + 1)]
public string Remark;
[MarshalAs(UnmanagedType.LPWStr, SizeConst = 128 + 1)]
public string Program;
public int iLine;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128 + 1)]
public string Title;
public int iNbEntity;
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct)] // c'est ici où ca coince ??
public CS_StructReportEntity[] pEntity;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
internal class CS_StructReponse
{
public int iLastErrorCode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024 + 1)]
public string LastError;
public int iNbReport;
public int iDetectionId;
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct)]
public CS_StructReport[] pReport;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
internal class CS_StructRequest
{
public string pData;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256 + 1)]
public string Addresse;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100 + 1)]
public string City;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100 + 1)]
public string Country;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50 + 1)]
public string Format;
public string pContext;
public int iAlert;
public int iRank;
}
[DllImport(_CheminAPI)]
private static extern void maFonction(IntPtr pRequest, IntPtr pResponse);
public static int CS_maFonction(ref CS_StructReponse Request,
ref CS_StructRequest Response)
{
int retour;
IntPtr pRequest = Marshal.AllocHGlobal(Marshal.SizeOf(Request));
IntPtr pResponse = Marshal.AllocHGlobal(Marshal.SizeOf(Response));
try
{
Marshal.StructureToPtr(Request, pRequest, false);
Marshal.StructureToPtr(Response, pResponse, false);
retour = maFonction(pRequest, pResponse);
if (pRequest != IntPtr.Zero)
{
Marshal.PtrToStructure(pRequest, Request);
}
else
{
//code
}
if (pResponse != IntPtr.Zero)
{
Marshal.PtrToStructure(pResponse, Response);
}
else
{
//code
}
}
catch (System.Exception ex)
{
//gestion de lexception
}
finally
{
Marshal.FreeHGlobal(pRequest);
Marshal.FreeHGlobal(pResponse);
}
return retour;
} |
Partager