A customer asked:


Is there a way in VFP to pass a DWORD to an API function from VFP?


The Beep API function used in Create your own typing tutor! uses DWORDs and is called via the DECLARE - DLL Command . A DWORD is just a 32 bit value. An integer in VFP is a 32 bit value (4 bytes).


DECLARE integer Beep IN WIN32API integer Freq, integer DurationMs



Other examples of 32 bit values in the Win API abound. A LPDWORD is a Long Pointer to a DWORD, which is a 32 bit value as well (on a 32 bit machine).


See the Windows Data Types MSDN topic for more details.


The Data Type Ranges topic shows the sizes of the various types.  For example, an HWND is a HANDLE which is a PVOID which is a void * which means a pointer to anything. A pointer is 32 bits (on a 32 bit machine).


The SetWindowText Function is declared:


BOOL SetWindowText(      
    HWND hWnd,
    LPCTSTR lpString

and thus is called:


DECLARE integer SetWindowText IN WIN32API integer,string




A VFP string is just a sequence of bytes. If a Windows API requires a structure to be passed, just pass a string of the right size. For example, see Inspect your memory image and see fragmentation for a call to VirtualQueryEx  which returns a MEMORY_BASIC_INFORMATION structure. That structure is simply a sequence of bytes, so the DECLARE command looks like:


DECLARE integer VirtualQueryEx IN WIN32API integer hProcess, integer lpAddress,string @, integer dwLength


To decode/encode the string the CTOBIN( ) Function and the BINTOC( ) Function are very useful.