testwmtx.prg is an example of why not work wapi_GetLastError() .-
--- testwmtx.prg
STATIC s_hMutex
PROCEDURE Main()
LOCAL cAppName
// It may be a random program name :)
hb_FNameSplit( hb_ProgName(), NIL, @cAppName )
s_hMutex := wapi_CreateMutex( NIL, NIL, cAppName )
IF ! Empty( s_hMutex ) .AND. wapi_GetLastError() == 0
? cAppName, "=> Hello World! OK."
ELSE
? cAppName, "=> Application is running. Error", wapi_GetLastError()
ENDIF
WAIT
RETURN
---
In the second instance of the application fails because wapi_GetLastError()
return 0.
Compiling in MT mode, not define HB_USE_TLS and in Windows of course.
_*WHAY*_
wapi_CreateMutex() call CreateMutex() Windows API function.
CreateMutex() set the last error code to 183 ERROR_ALREADY_EXISTS (Is Ok the
mutex already exit in the second instance).
But wapi_CreateMutex() return with hb_ret* and this functions call hb_xgrab().
hb_xgrab() and MT mode call hb_mspace() and this call hb_stackAllocator().
hb_stackAllocator() call hb_stack_ready().
hb_stack_ready() call hb_tls_get() and hb_tls_get() is defined with
TlsGetValue().
Windows API function TlsGetValue() in Header Winbase.h
How to work with TlsGetValue() .-
http://msdn.microsoft.com/en-us/library/ms686812%28VS.85%29.aspx
"
The TlsGetValue function calls SetLastError to clear a thread's last error when
it succeeds.
"
TlsGetValue() set the last error code to 0 that is returned by
wapi_GetLastError().
Not Ok, the Application is running.
IMHO this is irrelevant, I don't like to limit Harbour internal to NOT WORK
with Windows APIs.
So I tried to update the repository with an implementation that supports in wapi_* for Windows API Last Error codes and plans to
update (pre-alloc the memory) without success.
Please, grant access to ID jarabal in sourceforge.net to update the repository.
Thanks. :)
--
Xavi
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour