Bonjour à tous,
J'essaye d'appeler une DLL écrite en A à partir d'un program C# mais j'ai une errur çà l'exécution.
Voici le contenu de ma DLL C :
et voici mon code c# :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 /* file test.h */ #define DLL_EXPORT __declspec(dllexport) DLL_EXPORT struct struct_test{ int a; int b; }; DLL_EXPORT int func_test(struct struct_test * t); /*********************************************/ /* file test.c */ #include "test.h" DLL_EXPORT int func_test(struct struct_test * t) { return t->a+t->b; }
L'erreur renvoyée est la suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 using System; using System.Runtime.InteropServices; public class csharp_test_class { [StructLayout(LayoutKind.Sequential, Pack=1)] public struct struct_test{ public int a; public int b; }; [DllImport("test")] public extern static int func_test( ref struct_test t ); public static void Main() { struct_test t = new struct_test(); t.a = 3; t.b = 4; Console.WriteLine(func_test(ref t)); } }
Quelqu'un a-t-il une idée pour résoudre ce problème ?PInvokeStackImbalance was detected :
A call to PInvoke function 'Project1!csharp_test_class::func_test' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
D'avance merci pour vos réponse,
Bien à vous,
Yan302
Partager