[fpc-pascal] Re: Does GetLastError in WinCE work? NO answer??

Sven Barth svenmauren at vr-web.de
Wed Nov 4 19:37:59 CET 2009


Hi!

 > Hello
 > I get strange results form GetLasError in WinCe;
 > something like 1449435930, for example;
 >
 > I use this:
 > {$include d:\lazarus\fpc\2.2.4\source\rtl\wince\wininc\coredll.inc}
 > function GetLastError:DWORD; external KernelDLL name 'GetLastError';
 >
 > var
 >  err: dword;
 >
 > begin
 >     MutexHandle := CreateMutex(NIL, TRUE, 'xxx');
 >     err:= GetCeError;
 >     if err = ERROR_ALREADY_EXISTS  THEN BEGIN
 >       SetForegroundWindow(FindWindow('xxx', ''));
 >       CloseHandle(MutexHandle);
 >       Application.BringToFront;
 >     END ELSE BEGIN
 >       .........
 > Am I missing something?
 > Why do I get those huge values from GetLastError?
 > Thanks for any help

1. why do you use "{$include ...}"? Just add the unit "windows" to the 
uses clause of your program - if it isn't already

2. why do you redeclare "GetLastError" when you're already including the 
file which contains the import? (but the first point is more important)

3. why are you using "GetCeError" while you want to use "GetLastError"? 
("GetLastError" is the correct one in this context by the way)

4. you can't use the "Get*Error" methods like this. You first have to 
check whether the result of "CreateMutex" is valid (e. g. check if it is 
"0" or "INVALID_HANDLE_VALUE" - I don't know which one is used here... 
please check the MSDN for this bit of info ;) ). If the check is not 
valid (e.g. "MutexHandle" is "0"/"INVALID_HANDLE_VALUE") THEN you can 
use "Get*Error".

I hope I was able to help you.

Regards,
Sven



More information about the fpc-pascal mailing list