Suite à ce post, je pense avoir résolu mon pb de marshalling bien que j'ai tjrs un pb...
Voici les modifs que j'ai faite:
Dans ma fichier de déclaration
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
| /* InformationsPorteur */
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CPS_InfosPorteur
{
public Byte[] CodeCivilite; // [2];
public Byte[] NomPatronym; // [27];
public Byte[] NomMarital; // [27];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public PrenomsArray[] Prenoms; // [3][27];
public Byte[] PrenomUsuel; // [27];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public CodesLanguesArray[] CodeLangues; // [4][2];
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PrenomsArray
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 27)]
public Byte[] Prenom;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CodesLanguesArray
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public Byte[] CodeLangue;
} |
Dans la fonction qui appelle la dll
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
CPS_InfosPorteur Porteur = new CPS_InfosPorteur();
Porteur.CodeCivilite = new Byte[2];
Porteur.NomPatronym = new Byte[27];
Porteur.NomMarital = new Byte[27];
Porteur.Prenoms = new PrenomsArray[3];
for (int i = 0; i < 3; i++)
{
Porteur.Prenoms[i].Prenom = new Byte[27];
}
Porteur.PrenomUsuel = new Byte[27];
Porteur.CodeLangues = new CodesLanguesArray[4];
for (int i = 0; i < 4; i++)
{
Porteur.CodeLangues[i].CodeLangue = new Byte[2];
}
CpsCmdReturnValue = ApiCps.CPS_InformationsPorteur(CpsNumSession, ref Porteur, ref CpsStatusService,ref CpsEtatCarte); |
Pour infos, voici la déclaration de la fonction de la dll
1 2
| [DllImport("System\\cpsw32.dll", EntryPoint = "#8", CharSet = CharSet.Ansi)]
public static extern UInt16 CPS_InformationsPorteur(UInt16 NumSession, ref CPS_InfosPorteur InfosPorteur, ref CPS_StatusService StatusService, ref UInt16 EtatCarte); |
A l'exécution, je me prend une Exception AccesViolationException
Tentative de lecture ou d'écriture de mémoire protégée. Cela indique souvent qu'une autre mémoire est endommagée.
Etant certains des autres paramètres déclarés dans ma fonction, je me dis qu'il doit encore y avoir un souci dans la déclaration de la structure Porteur mais je ne vois pas bien où.
Si j'enleve le Ref de Porteur, l'exécution passe mais forcément la structure n'est pas initialisée... Que faire ?
Partager