Re: Call DLL sets WinLastError to 203
Hi Jeff,
> Also, I ran that same test.exe on 3 different machines. Without the
> SetLastError(), all return 2.
Thanks for testing.
Yes, that's correct. It returns "2" in this case. And if you add a simple
"Display Message Box" before the "Call DLL" function then it returns "0".
For example:
Display Message Box "Ready..." -- ""
We do not set the error-value from the runtime, Windows handles this
automatically. GetLastError() always returns the last-error code value. If
last-error value is ERROR_ENVVAR_NOT_FOUND then Windows set it to this value
(for whatever reason) in one of the previous Windows API calls.
Thanks again.
Friedrich
Re: Call DLL sets WinLastError to 203
I had noticed the messagebox thing as well, because I was going to
offer a choice of whether to call SetLastError(). However, it seemed I
was always answering yes<g>
Jeff Slarve
www.jssoftware.com
www.twitter.com/jslarve
I'll search help files & Google for you.
Re: Call DLL sets WinLastError to 203
> I had noticed the messagebox thing as well, because I was going to
> offer a choice of whether to call SetLastError(). However, it seemed I
> was always answering yes<g>
<G> :-)
Friedrich
Re: Call DLL sets WinLastError to 203
Thank you. This information leads me to the following workaround:
Set Variable %KERNEL32HANDLE% to FUNCTION:Load DLL("kernel32.dll")
Call DLL "%KERNEL32HANDLE%" -- Function "SetLastError" (long) (0)
Call DLL "%KERNEL32HANDLE%" -- Function "GetLastError" () ()
Markus Zander
Re: Call DLL sets WinLastError to 203
> Thank you. This information leads me to the following workaround:
>
> Set Variable %KERNEL32HANDLE% to FUNCTION:Load DLL("kernel32.dll")
> Call DLL "%KERNEL32HANDLE%" -- Function "SetLastError" (long) (0)
> Call DLL "%KERNEL32HANDLE%" -- Function "GetLastError" () ()
The main question is, why does LoadLibrary() succeed on this machine but
sets the last-error value to ERROR_ENVVAR_NOT_FOUND. If I were you, I would
try to pass a fully qualified DLL name (instead of kernel32.dll) to see if
that helps. This seems to be a machine specific problem (perhaps there is
something wrong with the DLL search strategy on this machine).
Just for the records: this is NOT caused by a SetupBuilder bug! Because the
LoadLibrary Windows API really sets the last-error value to
ERROR_ENVVAR_NOT_FOUND, the GetLastError "Call Dll..." script function
returns the correct error code here.
Friedrich
Re: Call DLL sets WinLastError to 203
> try to pass a fully qualified DLL name (instead of kernel32.dll) to see if
Already tried this morning - without success.
Markus Zander
Re: Call DLL sets WinLastError to 203
>> try to pass a fully qualified DLL name (instead of kernel32.dll) to see
>> if
>
> Already tried this morning - without success.
>
Aha, okay. I have Goggled and there are a few threads related to this
issue. But there is no solution mentioned.
BTW, here is an interesting source code snipped. I think what happens on
this machine is that Windows tries to retrieve (as part of the LoadLibrary
call) the name of the system folder and this process fails (for unknown
reasons) with error ERROR_ENVVAR_NOT_FOUND. LoadLibrary itself succeeds,
but the last-error value is not "cleared".
Friedrich
Re: Call DLL sets WinLastError to 203
Could it be a constructor in the DLL?
Jeff Slarve
www.jssoftware.com
www.twitter.com/jslarve
I'll search help files & Google for you.
Re: Call DLL sets WinLastError to 203
Hi Jeff,
>
> Could it be a constructor in the DLL?
>
To be honest, I have no idea. The funny thing is, the LoadLibrary Windows
API sets this last-error value ERROR_ENVVAR_NOT_FOUND when it loads the
kernel32 (the Windows Kernel). The LoadLibrary call succeeds, but the
last-error value is set. Does not make any sense and is against "the rules"
<g>. If LoadLibrary succeeds, the last error code "should" not be touched.
Friedrich
Re: Call DLL sets WinLastError to 203
> FWIW, I get a %_SB_RETURN% of 2 if I comment out the SetLastError and
> zero with the SetLastError() in place.
I have changed this behavior in the latest internal build. The runtime
initialization "clears" the error buffer now.
---
CHANGE : After the internal runtime initialization process, the
last-error value is reset to 0.
---
Friedrich