Bonjour à tous,
Je tente de convertir un header C win32 pour utiliser un DLL.
A priori, ça ne fonctionne pas très bien. Si quelqu'un voit les erreurs... Car le C, n'est vraiment pas ma tasse de thé...
Voici le header C:
Voici ma tentative de conversion:
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
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 #ifdef __cplusplus extern "C" { #endif typedef enum { WPS_OK = 0, WPS_ERROR_SCANNER_NOT_FOUND = 1, WPS_ERROR_WIFI_NOT_AVAILABLE = 2, WPS_ERROR_NO_WIFI_IN_RANGE = 3, WPS_ERROR_UNAUTHORIZED = 4, WPS_ERROR_SERVER_UNAVAILABLE = 5, WPS_ERROR_LOCATION_CANNOT_BE_DETERMINED = 6, WPS_ERROR_PROXY_UNAUTHORIZED = 7, WPS_ERROR_FILE_IO = 8, WPS_ERROR_INVALID_FILE_FORMAT = 9, WPS_ERROR_TIMEOUT = 10, WPS_NOT_APPLICABLE = 11, WPS_GEOFENCE_ERROR = 12, WPS_NOMEM = 98, WPS_ERROR = 99 } WPS_ReturnCode; typedef struct { const char* username; const char* realm; } WPS_SimpleAuthentication; typedef enum { WPS_NO_STREET_ADDRESS_LOOKUP, WPS_LIMITED_STREET_ADDRESS_LOOKUP, WPS_FULL_STREET_ADDRESS_LOOKUP } WPS_StreetAddressLookup; typedef struct { char* name; char code[3]; } WPS_NameCode; typedef struct { char* street_number; char** address_line; char* city; char* postal_code; char* county; char* province; WPS_NameCode state; char* region; WPS_NameCode country; } WPS_StreetAddress; typedef enum { WPS_LOCATION_TYPE_2D, WPS_LOCATION_TYPE_3D } WPS_LocationType; typedef struct { //@{ double latitude; double longitude; //@} double hpe; unsigned short nap; double speed; double bearing; WPS_StreetAddress* street_address; unsigned short ncell; unsigned short nsat; double altitude; WPS_LocationType type; unsigned long age; } WPS_Location; WPSAPI_EXPORT WPS_ReturnCode WPSAPI_CALL WPS_location(const WPS_SimpleAuthentication* authentication, WPS_StreetAddressLookup street_address_lookup, WPS_Location** location); WPSAPI_EXPORT void WPSAPI_CALL WPS_free_location(WPS_Location*); #ifdef __cplusplus } #endif
En particulier, mes questions portent sur les points suivants:
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
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 WPS_StreetAddressLookup = ( WPS_NO_STREET_ADDRESS_LOOKUP, WPS_LIMITED_STREET_ADDRESS_LOOKUP, WPS_FULL_STREET_ADDRESS_LOOKUP ); WPS_ReturnCode = ( WPS_OK = 0, WPS_ERROR_SCANNER_NOT_FOUND = 1, WPS_ERROR_WIFI_NOT_AVAILABLE = 2, WPS_ERROR_NO_WIFI_IN_RANGE = 3, WPS_ERROR_UNAUTHORIZED = 4, WPS_ERROR_SERVER_UNAVAILABLE = 5, WPS_ERROR_LOCATION_CANNOT_BE_DETERMINED = 6, WPS_ERROR_PROXY_UNAUTHORIZED = 7, WPS_ERROR_FILE_IO = 8, WPS_ERROR_INVALID_FILE_FORMAT = 9, WPS_ERROR_TIMEOUT = 10, WPS_NOT_APPLICABLE = 11, WPS_GEOFENCE_ERROR = 12, WPS_NOMEM = 98, WPS_ERROR = 99); WPS_LocationType = (WPS_LOCATION_TYPE_2D, WPS_LOCATION_TYPE_3D); WPS_SimpleAuthentication = Record username: PChar; realm: PChar; End; WPS_NameCode = Record name: PChar; code: array[0..2] of Char; End; PPchar = array [0..0] of PChar; WPS_StreetAddress = Record street_number: PChar; address_line: PPChar; city: PChar; postal_code: PChar; county: PChar; province: PChar; state: WPS_NameCode; region: PChar; contry: WPS_NameCode; End; TWPS_Location = record hpe : double; // Précision en mètres nap: word; // Nb de point d'accès utilisés speed: double; // Vitesse en Km/h bearing: double; // Rotation street_addresse: ^WPS_StreetAddress; ncell: Word; // Nb d'antennes GSM utilisées nsat: Word; // Nb de satellites GPS utilisés altitude: double; loctype : WPS_LocationType; age: LongInt; latitude : double; longitude : double; end; PTWPS_Location = ^TWPS_Location; function WPS_location ( const authentication :WPS_SimpleAuthentication; street_address_lookup: WPS_StreetAddressLookup; location: PTWPS_Location):WPS_ReturnCode; stdcall; external 'wpsapi.dll'; procedure WPS_free_location (location: PTWPS_Location) stdcall; external 'wpsapi.dll'; procedure GetWifiLoc; var authentication : WPS_SimpleAuthentication; location: PTWPS_location; retour : WPS_ReturnCode; Begin authentication.username := 'XXXXXX'; authentication.realm := 'YYYYY'; retour := WPS_location(&authentication, PS_LIMITED_STREET_ADDRESS_LOOKUP, &location); if retour = WPS_OK then begin WPS_free_location(&location); end; End;
Undoit-il être traduit par un
Code : Sélectionner tout - Visualiser dans une fenêtre à part char** c
ou par un
Code : Sélectionner tout - Visualiser dans une fenêtre à part c : ^PChar?
Code : Sélectionner tout - Visualiser dans une fenêtre à part c : array[0..0] of PChar
Quelle est la signification du //@ dansSachant que dans la documentation, ces deux champs sont à la fin de la structure mais que dans le header ils sont en tête.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 //@{ double latitude; double longitude; //@}
Voici la doc :
Enfin, au niveau de l'appel de la fonction en 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 9.3 WPS_Location Struct Reference #include <wpsapi.h> Data Fields double hpe unsigned short nap double speed double bearing WPS_StreetAddress street_address unsigned short ncell unsigned short nsat double altitude WPS_LocationType type unsigned long age double latitude double longitude
les traductions de déclaration et d'appel Delphi sont-elles ok ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 WPS_location(const WPS_SimpleAuthentication* authentication, WPS_StreetAddressLookup street_address_lookup, WPS_Location** location);
Merci d'avance de vos avis.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 // Déclaration function WPS_location ( const authentication :WPS_SimpleAuthentication; street_address_lookup: WPS_StreetAddressLookup; location: PTWPS_Location):WPS_ReturnCode; stdcall; external 'wpsapi.dll'; // Appel retour := WPS_location(&authentication, WPS_LIMITED_STREET_ADDRESS_LOOKUP, &location);
André.
Partager