Hi All,
testwmtx.prg may not work because Harbour internal can call Windows API and setting
"Last Error".
[I think in MT mode, with hbvmmt, does not work].
"
Some functions set the last error code to 0 on success and others do not.
You should call the GetLastError function immediately when a function's return.
"
This means that wapi_GetLastError() can not be a wrapper 1:1 to Windows API
GetLastError().
Two solutions .-
One is to maintain a dynamic variable, thread safe, for each thread/process to store last error and return this value in
wapi_GetLastError().
And another solution is to return last error as the last parameter of each wrapper function to Windows API that can set and
remove wapi_GetLastError() because returns values can not be true.
IMHO to Harbour this latter solution is probably the most easiest and effective
in terms of performance.
For example, with this solution testwmtx.prg would be like this .-
STATIC s_hMutex
PROCEDURE Main()
LOCAL cAppName, nLastError
// It may be a random program name :)
hb_FNameSplit( hb_ProgName(), NIL, @cAppName )
s_hMutex := wapi_CreateMutex( NIL, NIL, cAppName, @nLastError )
IF ! Empty( s_hMutex ) .AND. nLastError == 0
? cAppName, "=> Hello World! OK."
ELSE
? cAppName, "=> Application is running. Error", nLastError
ENDIF
WAIT
RETURN
What do you think about this, comments?
--
Xavi
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour