Many Windows APIs can fail for various reasons. For example FormatMessage indicates failure by returning 0. (see GetLastError is a number. What does it mean?) To get further information about the failure, call the GetLastErrror API, which queries the value set by the last SetLastError call.  One can imagine that these APIs call SetLastError to initialize the Last Error value to 0. If an error occurs, this value is changed appropriately.

 

The problem is that the Last Error is a global value, being set and reset by Windows API calls. Behind the scenes FoxPro calls the Win API for many services such as memory management, I/O, etc. Also, Windows sends Fox messages for many services (such as paint the window!) which cause Fox to call Windows API functions. Also, APIs can call other APIs. That means between executing lines of your fox code, many Windows API calls could have been called, possibly changing the Last Error value. Thus the GetLastError truly does get the “Last Error”, but there may have been many intervening calls after the call your code makes that failed.

 

I changed VFP9 so that this global value is isolated to your code. If you call GetLastError and SetLastError, they will reflect the last DLL call, regardless of intervening API calls.

 

VBA and VB.Net both have a LastDLLError property to achieve the same goal.