Certainly it's not an easy job when you just started, but in fact it's not too bad. Let's begin with a very simple structure:
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
By definition WORD occupies 2 bytes. That means size of this structure is 16 bytes. API function GetSystemTime retrieves the current day and time. Call it this way:
DECLARE GetSystemTime IN kernel32 STRING @lpSystemTime
lcBuffer = Repli(Chr(0), 16) && those 16 bytes
= GetSystemTime(@lcBuffer)
Now, when you have your buffer filled with data, cut it by WORD pieces (8 pcs by two chars) and convert each piece to a numeric. First char is the LO byte, and second is HI byte. Here is a function:
FUNCTION buf2word (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
Asc(SUBSTR(lcBuffer, 2,1)) * 256
And finally the whole program code that returns current date/time using a call to external function passing a structure:
DECLARE GetSystemTime IN kernel32 STRING @lpSystemTime
lcBuffer = Repli(Chr(0), 16) && those 16 bytes
= GetSystemTime(@lcBuffer)
FOR ii=0 TO 7
? buf2word(SUBSTR(lcBuffer, ii*2+1, 2))
ENDFOR
FUNCTION buf2word (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
Asc(SUBSTR(lcBuffer, 2,1)) * 256
* * *
Of course, except WORD there is a lot more: DWORD, LPTSTR, HANDLE, ULONG, TCHAR, ... no way to stop :)
* * *
Check more examples with even more complex structures on my site "Using Win32 Functions in Visual FoxPro" at
http://www.news2news.com/vfpSearch 'typedef struct'.
Regards!
Anatoliy Mogylevets
devicecontext@msn.com