Information générale
Catégorie:
Fonctions Windows API
Titre:
Help converting returned values
I copied the following from VFP Help:
This example illustrates calling the Windows API function GetSystemTime. GetSystemTime fills in a structure of WORD (16-bit unsigned integer) values with system time information.
C Function Declaration and Struct Definition
VOID GetSystemTime(
LPSYSTEMTIME lpSystemTime // address of system time structure
);
This is the struct definition:
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
Calling the Function in Visual FoxPro
The Visual FoxPro code passes GetSystemTime, a reference to a character variable, which is filled in with the WORD values.
* Visual FoxPro Code: cmdSystemTime.Click
DECLARE INTEGER GetSystemTime IN win32api STRING @
cBuff=SPACE(40)
GetSystemTime(@cBuff)
To retrieve the information from the character variable, cBuff, the following code converts 8-bit ASCII characters for year and month in the variable into 16-bit equivalents.
THIS.Parent.lblYear.Caption = ALLTRIM(STR(ASC(SUBSTR(cBuff,2)) * 256 + ASC(SUBSTR(cBuff,1))))
THIS.Parent.lblMonth.Caption = MONTH_LOC + ALLTRIM(STR(ASC(SUBSTR(cBuff,4)) * 256 + ASC(SUBSTR(cBuff,3))))
My question:
I need to understand the ALLTRIM(STR(ASC(SUBSTR(cBuff,2)) * 256 + ASC(SUBSTR(cBuff,1)))) statements.
Can someone explain the 2 and 1 in the first statement and the 4 and 3 in the second statement? I know that it is saying to capture some particular portion of cbuff. What I do not understand is why those particular characters.
And, why is the first part of each statement multiplied by 256 but not the second part?
Thanks,
John
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement