Use API Functions that Require a STRUCT

File: SAMPLES\SOLUTION\WINAPI.SYSTIME.SCX

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))))