Author Topic: LastDLLError  (Read 2666 times)

DAG_P6

  • Full Member
  • ***
  • Posts: 184
  • WinBatch rocks, and so does Wilson WindowWare!
    • WizardWrx
LastDLLError
« on: September 15, 2013, 01:23:29 am »
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

  • Sr. Member
  • ****
  • Posts: 280
Re: LastDLLError
« Reply #1 on: September 16, 2013, 04:17:38 am »
((( "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

  • Tech Support
  • *****
  • Posts: 3016
    • WinBatch
Re: LastDLLError
« Reply #2 on: September 16, 2013, 06:55:53 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

  • Full Member
  • ***
  • Posts: 184
  • WinBatch rocks, and so does Wilson WindowWare!
    • WizardWrx
Re: LastDLLError
« Reply #3 on: September 16, 2013, 04:58:00 pm »
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.