Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Type..end type in VB to Visual Fox Pro 9
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
01380003
Message ID:
01380010
Vues:
25
VFP does not support structures directly. You have to convert structure to a string buffer and pass it to external function as STRING@ or STRING depending on whether values in the structure are to be modified inside the call.

This is the AC_INFO structure in C terms
typedef struct {
	int	nMaxC;			// Maximum number of command data bytes
	int	nMaxR;			// Maximum number of dat bytes that can be requested in a response
	int	CType;			// The card types supported by the ACR10
	BYTE	CStat;			// The status of the card reader
	BYTE	CSel;			  // The current selection of card type
	BYTE	szRev[10];	// The 10 bytes ACR10 firmware type and revision code
	int nLibVer;		// Library version (e.g. 310 is equal to version 3.10)
  long  lBaudRate;  // Current Running Baud Rate
} AC_INFO;
Assuming that each int takes 2 bytes, each BYTE takes 1 byte, and the long takes 4 bytes; the length of the string buffer is (2 + 2 + 2 + 1 + 1 + 10 + 2 + 4) = 24 bytes
* allocating a string buffer of 24 bytes
cBuffer = REPLICATE(CHR(0), 24)

* declaring the function
* DLLAPI int AC_decl AC_GetInfo(int, AC_INFO *);
DECLARE SHORT AC_GetInfo IN mcr930 SHORT, STRING@

* calling the function
nResult = AC_GetInfo(hReader, @cBuffer)
If the call is successful, we assume that the cBuffer is populated with values. The cBuffer is still a string. To get the numeric values from it use CTOBIN() or similar functions.

For example, the value of nMaxR occupies bytes 3 to 4 in the cBuffer. In Windows the lowest byte comes first. Which makes the conversion from string back to number performed as follows:
nMaxR = ASC(SUBSTR(cBuffer,3,1)) +;
	ASC(SUBSTR(cBuffer,4,1)) * 256
You can find multiple code samples dealing with structures in VFP on my web site. For example,
Get the power status of your laptop computer
http://news2news.com/vfp/?example=6

Extended OS Version info
http://news2news.com/vfp/?example=23
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform