Bjr à tous,

J'utilise une librairie DLL (phidgets21.dll), fournie avec un fichier d'entête C/C++.

Certaines fonctions de cette DLL ont un prototype de la forme:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
__declspec (dllimport)   int __stdcall CPhidget_set_OnAttach_Handler (CPhidgetHandle phid, int (__stdcall * fptr) (CPhidgetHandle phid, void *userPtr), void *userPtr);
prototype dans lequel se trouve une fonction imbriquée dans la liste des paramètres.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
type CInteger = type Integer;
type TFunctionStdCallFPtr      = function(phid: CPhidgetHandle; userPtr: Pointer): CInteger; stdcall;
type PTFunctionStdCallFPtr     = Pointer; //^TFunctionStdCallFPtr;
//...
 function CPhidget_set_OnAttach_Handler(phid: CPhidgetHandle; fptr: PTFunctionStdCallFPtr; userPtr: Pointer): CInteger; stdcall; external PHIDGETS_LIBRARY;
Jusqu'ici, aucun problème.

Maintenant, j'ai un autre callback contenant une fonction imbriquée, avec réutilisation du paramètre data:
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
 
 
/**
 * Timestamp structure - usually initialized to 0.
 */
typedef struct _CPhidget_Timestamp
{
 int seconds;			/**< Number of seconds since timing began */
 int microseconds;		/**< Number of microseconds since last second passed - range is 0 - 999999 */
} CPhidget_Timestamp, *CPhidget_TimestampHandle;
//------------------
/**
 * Timestamped position data returned by the \ref CPhidgetSpatial_set_OnSpatialData_Handler event.
 */
     typedef struct _CPhidgetSpatial_SpatialEventData
     {
      double acceleration[3];	/**< Acceleration data for up to 3 axes. */
      double angularRate[3];   /**< Angular rate data (Gyroscope) for up to 3 axes */
      double magneticField[3];	 /**< Magnetic field data (Compass) for up to 3 axes */
      CPhidget_Timestamp timestamp;   /**< Hardware timestamp */
     } CPhidgetSpatial_SpatialEventData, *CPhidgetSpatial_SpatialEventDataHandle;
 
//...............
// 
__declspec (dllimport)
     int __stdcall CPhidgetSpatial_set_OnSpatialData_Handler (CPhidgetSpatialHandle phid,
							      int (__stdcall * fptr) (CPhidgetSpatialHandle phid, void *userPtr, CPhidgetSpatial_SpatialEventDataHandle * data, int dataCount),
							      void *userPtr);
Je sèche complètement sur deux points:
  • Alignement des structures
  • Comment traduire ce prototype en prototype Pascal


cdlt