LastDLLError

Started by DAG_P6, September 15, 2013, 01:23:29 AM

Previous topic - Next topic

DAG_P6

Context

I have developed a small set of WIL UDFs that implement wrappers around the Win32 mutex functions, a couple of which return useful diagnostic information through SetLastError.

Question

I have discovered, the hard way, that the Win32 GetLastError() function must be called right away, because the very next DLL call may trample it. My concern is that an intervening Windows API call, made on behalf of the WIL interpreter, over which I have no control, might trample the last error set by a DLLCall before a subsequent call, also via DllCall, to GetLastError, can retrieve it.

Is it safe to assume that the value returned by the native LastDLLError function is the result of a Windows API call to GetLastError that happens as part of the code that implements the WIL DLLCall function?
David A. Gray
You are more important than any technology.

kdmoyers

((( "a small set of WIL UDFs that implement wrappers around the Win32 mutex functions"  Sounds cool! )))
The mind is everything; What you think, you become.

td

Quote from: DAG_P6 on September 15, 2013, 01:23:29 AM

...

I have discovered, the hard way, that the Win32 GetLastError() function must be called right away, because the very next DLL call may trample it. My concern is that an intervening Windows API call, made on behalf of the WIL interpreter, over which I have no control, might trample the last error set by a DLLCall before a subsequent call, also via DllCall, to GetLastError, can retrieve it.

Is it safe to assume that the value returned by the native LastDLLError function is the result of a Windows API call to GetLastError that happens as part of the code that implements the WIL DLLCall function?

The value returned by LastDLLError is the system error state immediately after an assembly mov instruction has been issued to record the current stack pointer after the call to the dll entry point.  The saved stack pointer is then used for further error checking. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

DAG_P6

Thanks again, Tony. That was the answer I hoped (and expected) to receive.

I'll treat LastDllError as I would the value returned by the call to GetLastError that immediately follows any call to a routine that reports through SetLastError when I am coding in C or C++.
David A. Gray
You are more important than any technology.