Page 1 of 1
Problem with GetLastError()
Posted: Wed Sep 30, 2015 4:30 pm
by Psych
Seems like procedures which use debug statements clear the getlasterror value.
Also, any procedure which returns a string clears the value, even if the procedure is empty.
For debugging this can be critical.
Comment out the 'debug' inside the procedure and the call to the string function and see the error data is not affected.
Code: Select all
SetLastError_(2)
Procedure do_anything()
Debug "proc"
EndProcedure
Procedure$ string_function()
EndProcedure
do_anything()
string_function()
Debug "main"
Debug GetLastError_()
Might I suggest safeguarding system error information in future releases as to preserve debugging information.
Re: Problem with GetLastError()
Posted: Wed Sep 30, 2015 6:56 pm
by GPI
GetLastError_() is a windows-API-Function not a PB-Library-Function. You should only use this function after Windows-Api-Calls.
Re: Problem with GetLastError()
Posted: Wed Sep 30, 2015 7:23 pm
by Psych
I could not agree more, I am quite aware what GetLastError_() does.
That is my point.
Since we are in agreement that it's a windows API function and not a PB-Library function, why does PB clear/modify the GetLastError_() result?
The internal windows error code should only be modified by another API function (where applicable).
If a developer wishes to use to Windows API, it's use should not be sabotaged by PB behind the scenes.
Re: Problem with GetLastError()
Posted: Wed Sep 30, 2015 7:30 pm
by Danilo
PB functions use API internally, as well. For example, the Debug statement adds text to the debug output window, using an API call.
GetLastError_() is only valid directly after an API call.
Re: Problem with GetLastError()
Posted: Wed Sep 30, 2015 8:20 pm
by Psych
Danilo wrote:the Debug statement adds text to the debug output window, using an API call.
Interesting theory, but add comments to BOTH function calls.
Output will be 2.
Despite debugging the word 'main' to the debugger window.
In addition, calling the empty function that returns a string also invalidates API error values, despite the function doing nothing.
Maybe this is just a bug in the way functions are called/handled.
Re: Problem with GetLastError()
Posted: Thu Oct 01, 2015 5:21 am
by Danilo
Psych wrote:Interesting theory, but add comments to BOTH function calls.
I think it's even more complicated. Even internal string management functions could call API
for allocating and de-allocating memory/heap, copy memory/strings, etc.
Anyway, it's your feature request and I don't want to speak against it.
I just think for Set/GetLastError_() to work only with the WinAPI you use yourself in your PB code,
every single PB function (and internals like string management, debugger, etc.) that also use WinAPI
must preserve the WinAPI LastError state. This would/could probably affect nearly all functions.