2010-01-07 00:52 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbwin/win_err.c
  * contrib/hbwin/hbwin.h
  * contrib/hbwin/wapi_winbase_mutex.c
    * Changed low-level hbwin_SetLastError() to accept lasterror 
      as parameter.

  * contrib/hbwin/wapi_winbase.c
  * contrib/hbwin/wapi_winuser.c
    + Added internal handling of GetLastError(). This fixes lost
      GetLastError() values with apps linked with MT HVM.
      [ I didn't review wapi_commctrl.c, but some lazy checking
        on MSDN showed that these are generally not setting GetLastError(). ]
    * WAPI_GETSCROLLRANGE() now set ref params even in case of failure.
    ; TODO: Do some final renaming and rearrangement on the low-level.

  * contrib/hbwin/wapi_winbase_mutex.c
    * Formatting.
This commit is contained in:
Viktor Szakats
2010-01-06 23:59:16 +00:00
parent 2cc8ef44d5
commit c6ef8c62bb
6 changed files with 177 additions and 69 deletions

View File

@@ -17,6 +17,25 @@
past entries belonging to author(s): Viktor Szakats.
*/
2010-01-07 00:52 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbwin/win_err.c
* contrib/hbwin/hbwin.h
* contrib/hbwin/wapi_winbase_mutex.c
* Changed low-level hbwin_SetLastError() to accept lasterror
as parameter.
* contrib/hbwin/wapi_winbase.c
* contrib/hbwin/wapi_winuser.c
+ Added internal handling of GetLastError(). This fixes lost
GetLastError() values with apps linked with MT HVM.
[ I didn't review wapi_commctrl.c, but some lazy checking
on MSDN showed that these are generally not setting GetLastError(). ]
* WAPI_GETSCROLLRANGE() now set ref params even in case of failure.
; TODO: Do some final renaming and rearrangement on the low-level.
* contrib/hbwin/wapi_winbase_mutex.c
* Formatting.
2010-01-06 23:53 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbwin/win_err.c
! Fixed GetLastError() in MT mode.
@@ -327,7 +346,7 @@
* contrib/hbqt/generator/hbqtgen.prg
% Optimization to parameter list ptr conversion loop.
; TODO: Regenerate QT sources.
; TODO: Regenerate QT sources. [DONE]
2010-01-05 14:03 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/contrib/hbct/video.c
@@ -702,7 +721,7 @@
! Fixed to use hbwin_SetLastError().
; TODO: Call hbwin_SetLastError() after _all_ winapi
calls which modify lasterror value.
Until then, WAPI_GETLASTERROR() is broken.
Until then, WAPI_GETLASTERROR() is broken. [DONE]
* contrib/hbwin/hbwinole.h
+ Added self-guard.

View File

@@ -79,7 +79,7 @@
HB_EXTERN_BEGIN
HB_EXPORT void hbwin_SetLastError( void );
HB_EXPORT void hbwin_SetLastError( DWORD dwLastError );
HB_EXPORT DWORD hbwin_GetLastError( void );
HB_EXTERN_END

View File

@@ -79,16 +79,26 @@ HB_FUNC( WAPI_GETCURRENTTHREAD )
HB_FUNC( WAPI_WAITFORSINGLEOBJECT )
{
hb_retnl( WaitForSingleObject( wapi_par_HANDLE( 1 ), ( DWORD ) hb_parnl( 2 ) ) );
DWORD dwResult = WaitForSingleObject( wapi_par_HANDLE( 1 ), ( DWORD ) hb_parnl( 2 ) );
hbwin_SetLastError( GetLastError() );
hb_retnl( dwResult );
}
HB_FUNC( WAPI_WAITFORSINGLEOBJECTEX )
{
#if ! defined( HB_OS_WIN_CE )
hb_retnl( WaitForSingleObjectEx( wapi_par_HANDLE( 1 ), ( DWORD ) hb_parnl( 2 ), hb_parl( 3 ) ) );
DWORD dwResult;
DWORD dwLastError;
#if defined( HB_OS_WIN_CE )
dwResult = 0;
dwLastError = ERROR_INVALID_FUNCTION;
#else
hb_retnl( 0 );
dwResult = WaitForSingleObjectEx( wapi_par_HANDLE( 1 ), ( DWORD ) hb_parnl( 2 ), hb_parl( 3 ) );
dwLastError = GetLastError();
#endif
hbwin_SetLastError( dwLastError );
hb_retnl( dwResult );
}
HB_FUNC( WAPI_WAITFORMULTIPLEOBJECTS )
@@ -100,11 +110,15 @@ HB_FUNC( WAPI_WAITFORMULTIPLEOBJECTS )
{
HANDLE * handles = ( HANDLE * ) hb_xgrab( nLen * sizeof( HANDLE ) );
HB_SIZE nPos;
DWORD dwResult;
for( nPos = 0; nPos < nLen; ++nPos )
handles[ nPos ] = hb_arrayGetPtr( pArray, nPos + 1 );
hb_retnl( WaitForMultipleObjects( nLen, handles, hb_parl( 3 ), ( DWORD ) hb_parnl( 4 ) ) );
dwResult = WaitForMultipleObjects( nLen, handles, hb_parl( 3 ), ( DWORD ) hb_parnl( 4 ) );
hbwin_SetLastError( GetLastError() );
hb_retnl( dwResult );
hb_xfree( handles );
}
@@ -122,31 +136,44 @@ HB_FUNC( WAPI_WAITFORMULTIPLEOBJECTSEX )
{
HANDLE * handles = ( HANDLE * ) hb_xgrab( nLen * sizeof( HANDLE ) );
HB_SIZE nPos;
DWORD dwResult;
for( nPos = 0; nPos < nLen; ++nPos )
handles[ nPos ] = hb_arrayGetPtr( pArray, nPos + 1 );
hb_retnl( WaitForMultipleObjectsEx( nLen, handles, hb_parl( 3 ), ( DWORD ) hb_parnl( 4 ), hb_parl( 5 ) ) );
dwResult = WaitForMultipleObjectsEx( nLen, handles, hb_parl( 3 ), ( DWORD ) hb_parnl( 4 ), hb_parl( 5 ) );
hbwin_SetLastError( GetLastError() );
hb_retnl( dwResult );
hb_xfree( handles );
}
else
hb_errRT_BASE( EG_ARG, 1001, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
#else
hbwin_SetLastError( ERROR_INVALID_FUNCTION );
hb_retnl( 0 );
#endif
}
HB_FUNC( WAPI_SETPROCESSWORKINGSETSIZE )
{
#if ! defined( HB_OS_WIN_CE )
wapi_ret_L( SetProcessWorkingSetSize(
BOOL bResult;
DWORD dwLastError;
#if defined( HB_OS_WIN_CE )
bResult = FALSE;
dwLastError = ERROR_INVALID_FUNCTION;
#else
bResult = SetProcessWorkingSetSize(
wapi_par_HANDLE( 1 ) /* hProcess */,
( SIZE_T ) hb_parnint( 2 ) /* dwMinimumWorkingSetSize */,
( SIZE_T ) hb_parnint( 3 ) /* dwMaximumWorkingSetSize */ ) );
#else
wapi_ret_L( FALSE );
( SIZE_T ) hb_parnint( 3 ) /* dwMaximumWorkingSetSize */ );
dwLastError = GetLastError();
#endif
hbwin_SetLastError( dwLastError );
wapi_ret_L( bResult );
}
HB_FUNC( WAPI_GETLASTERROR )
@@ -156,8 +183,9 @@ HB_FUNC( WAPI_GETLASTERROR )
HB_FUNC( WAPI_SETLASTERROR )
{
SetLastError( ( DWORD ) hb_parnl( 1 ) );
hbwin_SetLastError();
DWORD dwLastError = ( DWORD ) hb_parnl( 1 );
SetLastError( dwLastError );
hbwin_SetLastError( dwLastError );
}
HB_FUNC( WAPI_SETERRORMODE )
@@ -168,32 +196,44 @@ HB_FUNC( WAPI_SETERRORMODE )
HB_FUNC( WAPI_LOADLIBRARY )
{
void * hFileName;
HMODULE hResult = LoadLibrary( HB_PARSTRDEF( 1, &hFileName, NULL ) );
hb_retptr( LoadLibrary( HB_PARSTRDEF( 1, &hFileName, NULL ) ) );
hbwin_SetLastError( GetLastError() );
hb_retptr( hResult );
hb_strfree( hFileName );
}
HB_FUNC( WAPI_FREELIBRARY )
{
hb_retl( FreeLibrary( ( HMODULE ) hb_parptr( 1 ) ) );
BOOL bResult = FreeLibrary( ( HMODULE ) hb_parptr( 1 ) );
hbwin_SetLastError( GetLastError() );
hb_retl( bResult );
}
HB_FUNC( WAPI_GETPROCADDRESS )
{
FARPROC pProc;
DWORD dwLastError;
#if defined( HB_OS_WIN_CE )
hb_retptr( NULL );
pProc = NULL;
dwLastError = ERROR_INVALID_FUNCTION;
#else
hb_retptr( ( void * ) GetProcAddress( ( HMODULE ) hb_parptr( 1 ), HB_ISCHAR( 2 ) ? ( LPCSTR ) hb_parc( 2 ) : ( LPCSTR ) ( HB_PTRDIFF ) hb_parnint( 2 ) ) );
pProc = GetProcAddress( ( HMODULE ) hb_parptr( 1 ), HB_ISCHAR( 2 ) ? ( LPCSTR ) hb_parc( 2 ) : ( LPCSTR ) ( HB_PTRDIFF ) hb_parnint( 2 ) );
dwLastError = GetLastError();
#endif
hbwin_SetLastError( dwLastError );
hb_retptr( ( void * ) pProc );
}
/* HMODULE WINAPI GetModuleHandle( __in_opt LPCTSTR lpModuleName ); */
HB_FUNC( WAPI_GETMODULEHANDLE )
{
void * hModuleName;
HMODULE hResult = GetModuleHandle( HB_PARSTR( 1, &hModuleName, NULL ) );
wapi_ret_HANDLE( GetModuleHandle( HB_PARSTR( 1, &hModuleName, NULL ) ) );
hbwin_SetLastError( GetLastError() );
wapi_ret_HANDLE( hResult );
hb_strfree( hModuleName );
}

View File

@@ -99,9 +99,9 @@ HB_FUNC( WAPI_CREATEMUTEX )
void * hName;
HANDLE hMutex = CreateMutex( ( LPSECURITY_ATTRIBUTES ) hb_parptr( 1 ), hb_parl( 2 ), HB_PARSTR( 3, &hName, NULL ) );
hbwin_SetLastError();
hbwin_SetLastError( GetLastError() );
wapi_mutex_ret( hMutex );
hb_strfree( hName );
}
@@ -112,9 +112,9 @@ HB_FUNC( WAPI_OPENMUTEX )
void * hName;
HANDLE hMutex = OpenMutex( hb_parnl( 1 ), hb_parl( 2 ), HB_PARSTR( 3, &hName, NULL ) );
hbwin_SetLastError();
hbwin_SetLastError( GetLastError() );
wapi_mutex_ret( hMutex );
hb_strfree( hName );
#else
hb_retptr( NULL );
@@ -129,7 +129,7 @@ HB_FUNC( WAPI_RELEASEMUTEX )
if( hMutex )
{
BOOL bResult = ReleaseMutex( hMutex );
hbwin_SetLastError();
hbwin_SetLastError( GetLastError() );
hb_retl( bResult );
}
else

View File

@@ -73,7 +73,9 @@ HB_FUNC( WAPI_MESSAGEBOX )
{
void * hStr1;
void * hStr2;
hb_retni( MessageBox( ( HWND ) hb_parptr( 1 ), HB_PARSTR( 2, &hStr1, NULL ), HB_PARSTR( 3, &hStr2, NULL ), hb_parni( 4 ) ) );
int iResult = MessageBox( ( HWND ) hb_parptr( 1 ), HB_PARSTR( 2, &hStr1, NULL ), HB_PARSTR( 3, &hStr2, NULL ), hb_parni( 4 ) );
hbwin_SetLastError( GetLastError() );
hb_retni( iResult );
hb_strfree( hStr1 );
hb_strfree( hStr2 );
}
@@ -83,7 +85,7 @@ HB_FUNC( WAPI_CREATEWINDOWEX )
void * hClassName;
void * hWindowName;
hb_retptr( CreateWindowEx(
HWND hResult = CreateWindowEx(
( DWORD ) hb_parnl( 1 ) /* dwExStyle */,
HB_PARSTRDEF( 2, &hClassName, NULL ),
HB_PARSTRDEF( 3, &hWindowName, NULL ),
@@ -95,7 +97,10 @@ HB_FUNC( WAPI_CREATEWINDOWEX )
HB_ISPOINTER( 9 ) ? ( HWND ) hb_parptr( 9 ) : HWND_DESKTOP /* hWndParent */,
( HMENU ) hb_parptr( 10 ) /* hMenu */,
( HINSTANCE ) hb_parptr( 11 ) /* hInstance */,
( LPVOID ) hb_parptr( 12 ) /* lpParam */ ) );
( LPVOID ) hb_parptr( 12 ) /* lpParam */ );
hbwin_SetLastError( GetLastError() );
hb_retptr( hResult );
hb_strfree( hClassName );
hb_strfree( hWindowName );
@@ -103,7 +108,9 @@ HB_FUNC( WAPI_CREATEWINDOWEX )
HB_FUNC( WAPI_DESTROYWINDOW )
{
hb_retl( DestroyWindow( ( HWND ) hb_parptr( 1 ) ) );
BOOL bResult = DestroyWindow( ( HWND ) hb_parptr( 1 ) );
hbwin_SetLastError( GetLastError() );
hb_retl( bResult );
}
/*-----------------------------------------------------------------------/
@@ -114,13 +121,21 @@ BOOL EnableScrollBar( HWND hWnd, UINT wSBflags, UINT wArrows );
*/
HB_FUNC( WAPI_ENABLESCROLLBAR )
{
#if ! defined( HB_OS_WIN_CE )
wapi_ret_L( EnableScrollBar( wapi_par_HWND( 1 ),
wapi_par_UINT( 2 ),
wapi_par_UINT( 3 ) ) );
BOOL bResult;
DWORD dwLastError;
#if defined( HB_OS_WIN_CE )
bResult = FALSE;
dwLastError = ERROR_INVALID_FUNCTION;
#else
wapi_ret_L( FALSE );
bResult = EnableScrollBar( wapi_par_HWND( 1 ),
wapi_par_UINT( 2 ),
wapi_par_UINT( 3 ) );
dwLastError = GetLastError();
#endif
hbwin_SetLastError( dwLastError );
wapi_ret_L( bResult );
}
/*----------------------------------------------------------------------*/
/*
@@ -148,6 +163,9 @@ HB_FUNC( WAPI_GETSCROLLBARINFO )
bSuccess = GetScrollBarInfo( wapi_par_HWND( 1 ),
wapi_par_LONG( 2 ),
sbi );
hbwin_SetLastError( GetLastError() );
if( bSuccess )
hb_storclen( ( char * ) &sbi, sizeof( SCROLLBARINFO ), 3 );
@@ -166,6 +184,9 @@ HB_FUNC( WAPI_GETSCROLLINFO )
bSuccess = GetScrollInfo( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
si );
hbwin_SetLastError( GetLastError() );
if( bSuccess )
hb_storclen( ( char * ) &si, 3, sizeof( SCROLLINFO ) );
@@ -177,12 +198,20 @@ int GetScrollPos( HWND hWnd, int nBar );
*/
HB_FUNC( WAPI_GETSCROLLPOS )
{
#if ! defined( HB_OS_WIN_CE )
wapi_ret_NI( GetScrollPos( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ) ) );
int iResult;
DWORD dwLastError;
#if defined( HB_OS_WIN_CE )
iResult = 0;
dwLastError = ERROR_INVALID_FUNCTION;
#else
wapi_ret_NI( 0 );
iResult = GetScrollPos( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ) );
dwLastError = GetLastError();
#endif
hbwin_SetLastError( dwLastError );
wapi_ret_NI( iResult );
}
/*----------------------------------------------------------------------*/
/*
@@ -190,25 +219,30 @@ BOOL GetScrollRange( HWND hWnd, int nBar, LPINT lpMinPos, LPINT lpMaxPos );
*/
HB_FUNC( WAPI_GETSCROLLRANGE )
{
#if ! defined( HB_OS_WIN_CE )
BOOL bSuccess;
DWORD dwLastError;
#if defined( HB_OS_WIN_CE )
bSuccess = FALSE;
dwLastError = ERROR_INVALID_FUNCTION;
#else
{
int minPos, maxPos;
if( GetScrollRange( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
&minPos,
&maxPos ) )
{
hb_storni( minPos, 3 );
hb_storni( maxPos, 4 );
bSuccess = GetScrollRange( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
&minPos,
&maxPos );
wapi_ret_L( HB_TRUE );
return;
}
dwLastError = GetLastError();
hb_storni( minPos, 3 );
hb_storni( maxPos, 4 );
}
#endif
wapi_ret_L( HB_FALSE );
hbwin_SetLastError( dwLastError );
wapi_ret_L( bSuccess );
}
/*----------------------------------------------------------------------*/
#if 0
@@ -258,10 +292,12 @@ int SetScrollPos( HWND hWnd, int nBar, int nPos, BOOL bRedraw );
*/
HB_FUNC( WAPI_SETSCROLLPOS )
{
wapi_ret_NI( SetScrollPos( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
wapi_par_INT( 3 ),
wapi_par_BOOL( 4 ) ) );
int iResult = SetScrollPos( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
wapi_par_INT( 3 ),
wapi_par_BOOL( 4 ) );
hbwin_SetLastError( GetLastError() );
wapi_ret_NI( iResult );
}
/*----------------------------------------------------------------------*/
/*
@@ -269,11 +305,13 @@ BOOL SetScrollRange( HWND hWnd, int nBar, int nMinPos, int nMaxPos, BOOL bRedraw
*/
HB_FUNC( WAPI_SETSCROLLRANGE )
{
wapi_ret_L( SetScrollRange( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
wapi_par_INT( 3 ),
wapi_par_INT( 4 ),
HB_ISLOG( 5 ) ? wapi_par_BOOL( 5 ) : TRUE ) );
BOOL bResult = SetScrollRange( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
wapi_par_INT( 3 ),
wapi_par_INT( 4 ),
HB_ISLOG( 5 ) ? wapi_par_BOOL( 5 ) : TRUE );
hbwin_SetLastError( GetLastError() );
wapi_ret_L( bResult );
}
/*----------------------------------------------------------------------*/
/*
@@ -281,13 +319,21 @@ BOOL ShowScrollBar( HWND hWnd, int wBar, BOOL bShow );
*/
HB_FUNC( WAPI_SHOWSCROLLBAR )
{
#if ! defined( HB_OS_WIN_CE )
wapi_ret_L( ShowScrollBar( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
wapi_par_BOOL( 3 ) ) );
BOOL bResult;
DWORD dwLastError;
#if defined( HB_OS_WIN_CE )
bResult = FALSE;
dwLastError = ERROR_INVALID_FUNCTION;
#else
wapi_ret_L( FALSE );
bResult = ShowScrollBar( wapi_par_HWND( 1 ),
wapi_par_INT( 2 ),
wapi_par_BOOL( 3 ) );
dwLastError = GetLastError();
#endif
hbwin_SetLastError( dwLastError );
wapi_ret_L( bResult );
}
/*----------------------------------------------------------------------*/
/*
@@ -295,7 +341,9 @@ HWND SetFocus( HWND hWnd );
*/
HB_FUNC( WAPI_SETFOCUS )
{
wapi_ret_HANDLE( SetFocus( wapi_par_HWND( 1 ) ) );
HWND hResult = SetFocus( wapi_par_HWND( 1 ) );
hbwin_SetLastError( GetLastError() );
wapi_ret_HANDLE( hResult );
}
/*----------------------------------------------------------------------*/
#if 0
@@ -319,5 +367,7 @@ HB_FUNC( WAPI_GETACTIVEWINDOW )
/*----------------------------------------------------------------------*/
HB_FUNC( WAPI_SETACTIVEWINDOW )
{
hb_retptr( SetActiveWindow( wapi_par_HWND( 1 ) ) );
HWND hResult = SetActiveWindow( wapi_par_HWND( 1 ) );
hbwin_SetLastError( GetLastError() );
hb_retptr( hResult );
}

View File

@@ -62,9 +62,8 @@ typedef struct
static HB_TSD_NEW( s_winerrData, sizeof( HB_WINERRDATA ), NULL, NULL );
void hbwin_SetLastError( void )
void hbwin_SetLastError( DWORD dwLastError )
{
DWORD dwLastError = GetLastError();
PHB_WINERRDATA pWinErrData = ( PHB_WINERRDATA ) hb_stackGetTSD( &s_winerrData );
pWinErrData->dwLastError = dwLastError;