Bonjour,

De quelle façon peut-on atteindre les fonctions d'une DLL écrite en C 32bits à partir d'un projet C#, j'ai bien trouvé DLLIMPORT(...) en C# mais je butte sur des problèmes de passage de paramètre char * => String, avec les IntPtr xnomfic=Marshal.AllocHGlobal(nomfic.Length + 1); et xnomfic=Marshal.StringToHGlobalAnsi(nomfic); j'obtiens une structure qui contient un char * mais cela ne correspond pas à mon prototype de fonction C qui et un char *.

Interface C 32bits

Code C : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
#ifdef __cplusplus
extern "C" {
#endif
__declspec( dllexport ) int loi_init(char *,WORD,WORD,WORD);  
#ifdef __cplusplus  
}  
#endif

en C#

Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
[DllImport("acti2loi.dll", CharSet = CharSet.Ansi)]
public static extern int loi_init(IntPtr nomfic,ushort lgnomfic, ushort traceok, ushort modeajout);
 
 
public Int16 x_loi_init(string nomfic, UInt16 lgnomfic, UInt16 traceok, UInt16 modeajout)
        {
            IntPtr xnomfic=Marshal.AllocHGlobal(nomfic.Length + 1);
            xnomfic=Marshal.StringToHGlobalAnsi(nomfic);
            int retour = 0;
            retour =loi_init(xnomfic,(ushort)lgnomfic,(ushort)traceok,(ushort)modeajout); 
            return ((Int16)retour);
        }


Merci d'avance
Yves