Valeur récupérée au travers d'une dll erronée
Bonjour,
Je suis entrain d'écrire une dll en C qui sera exploitée en VB.
Je me suis inspiré de cet excellent tutoriel pour commencer, mais je voudrais aller plus loin dans l'exploitation des structures en C.
Mon soucis est que je n'arrive pas à récuperer comme il faut certains élèment d'une structure (C) dans mon code en VB
Voici le code source de ma dll en C :
Code:
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
|
#define DLLEXPORT __declspec(dllexport) __stdcall
// DECLARATION structure perso
typedef struct poly
{
double a0;
double a1;
double a2;
double a3;
double a4;
double a5;
double a6;
double a7;
}poly;
// DECLARATION D'UNE STRUCTURE QUI CONTIENT DES STRUCTURES
typedef struct test_struct
{
double reel;
int entier;
poly p1;
}test_struct;
// FONCTION DE LA DLL
test_struct DLLEXPORT marcel(double a, int b, poly *p){
test_struct retour;
int i;
poly pol;
retour.reel=a+2.5;
retour.entier=b-1;
pol.a0=p->a0+0.1;
pol.a1=p->a1+0.11;
pol.a2=p->a2+0.111;
pol.a3=p->a3+0.1111;
pol.a4=p->a4+0.11111;
pol.a5=p->a5+0.111111;
pol.a6=p->a6+0.1111111;
pol.a7=p->a7+0.11111111;
retour.reel=p->a7+0.11111111;
retour.p1=pol;
return retour;
} |
L'exploitation de cette dll en C est fonctionnelle (pas de surprise dans les résultats renvoyé).
Par contre en VB, c'est autre chose... (note, je débute dans ce language...)
Déclaration dans un module :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
Public Const max_size As Integer = 2
Public Type poly
a0 As Double
a1 As Double
a2 As Double
a3 As Double
a4 As Double
a5 As Double
a6 As Double
a7 As Double
End Type
Public Type test_struct
r As Double
i As Integer
p1 As poly
End Type
Declare Function marcel Lib "dll.dll" (ByVal a As Double, ByVal B As Integer, p As poly) As test_struct |
Code source de la Form :
Code:
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
| Private Sub Form_Activate()
Dim a As Double
Dim i As Integer
Dim test As test_struct
Dim polynome As poly
a = 0.35
i = 1
polynome.a0 = 0.1
polynome.a1 = 0.1
polynome.a2 = 0.1
polynome.a3 = 0.1
polynome.a4 = 0.1
polynome.a5 = 0.1
polynome.a6 = 0.1
polynome.a7 = 0.1
test.r = a
test.i = i
test.p1 = polynome
test = marcel(0.35, 4, polynome)
Command1.Caption = Format$(test.p1.a2)
End Sub
Private Sub Command1_Click()
End
End Sub |
L'affichage dans le bouton me renvoie les valeurs attendues pour test.r et test.i, mais n'importe quoi pour le test.p1.a0, test.p1.a1, test.p1.a2 etc...
Une idée de ce qui ne va pas ?