From e18f4f39dbec97efa2ef9db8716bb4aaefc99c98 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 14 May 2009 18:11:14 +0000 Subject: [PATCH] 2009-05-14 20:08 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * contrib/hbwin/legacy.c + Added old MESSAGEBOX() call. * contrib/hbwin/win_misc.c * WAPI_MESSAGEBOX() now accepts pointer only. + WAPI_LOADLIBRARY() added, pointer based only. + WAPI_FREELIBRARY() added, pointer based only. + WIN_N2P() added to convert numeric pointers to real pointers. + WIN_P2N() added to convert real pointers to numeric ones. I know this is a hack but it's IMO better than embedding the conversion logic to all functions, and makes it possible to "bridge" this parameter passing difference between existing apps/libs and our developing Windows API layer. So f.e. 3rd party app may switch to our new API, while keeping some parts of his local code intact by using: WAPI_MESSAGEBOX( WIN_N2P( MYWINFUNC_RETURNING_A_NUMHND() ), "hello", "world", MB_OK ) Later after doing local fixes this can be changed to: WAPI_MESSAGEBOX( MYWINFUNC_PROPER(), "hello", "world", MB_OK ) * contrib/hbwin/win_dll.c * Changed stub order for DLLLOAD()/LOADLIBRARY(), DLLUNLOAD()/FREELIBRARY(), so that it workd if XBase++ parts are disabled. --- harbour/ChangeLog | 25 +++++++ harbour/contrib/hbwin/legacy.c | 14 ++-- harbour/contrib/hbwin/win_dll.c | 120 +++++++++++++++---------------- harbour/contrib/hbwin/win_misc.c | 24 ++++++- 4 files changed, 111 insertions(+), 72 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bd132cceb1..2794c6199c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,31 @@ past entries belonging to these authors: Viktor Szakats. */ +2009-05-14 20:08 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + * contrib/hbwin/legacy.c + + Added old MESSAGEBOX() call. + + * contrib/hbwin/win_misc.c + * WAPI_MESSAGEBOX() now accepts pointer only. + + WAPI_LOADLIBRARY() added, pointer based only. + + WAPI_FREELIBRARY() added, pointer based only. + + WIN_N2P() added to convert numeric pointers to real pointers. + + WIN_P2N() added to convert real pointers to numeric ones. + I know this is a hack but it's IMO better than embedding the + conversion logic to all functions, and makes it possible to + "bridge" this parameter passing difference between existing + apps/libs and our developing Windows API layer. + So f.e. 3rd party app may switch to our new API, while + keeping some parts of his local code intact by using: + WAPI_MESSAGEBOX( WIN_N2P( MYWINFUNC_RETURNING_A_NUMHND() ), "hello", "world", MB_OK ) + Later after doing local fixes this can be changed to: + WAPI_MESSAGEBOX( MYWINFUNC_PROPER(), "hello", "world", MB_OK ) + + * contrib/hbwin/win_dll.c + * Changed stub order for DLLLOAD()/LOADLIBRARY(), + DLLUNLOAD()/FREELIBRARY(), so that it workd if XBase++ parts + are disabled. + 2009-05-14 19:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/bin/hb-func.sh * respect HB_USER_LIBS creating hbmk.cfg diff --git a/harbour/contrib/hbwin/legacy.c b/harbour/contrib/hbwin/legacy.c index da2b23571d..7ef92deeee 100644 --- a/harbour/contrib/hbwin/legacy.c +++ b/harbour/contrib/hbwin/legacy.c @@ -115,14 +115,14 @@ HB_FUNC( SETLASTERROR ) SetLastError( hb_parnl( 1 ) ); } -#if 0 - -HB_FUNC_EXTERN( WAPI_MESSAGEBOX ); - /* Deprecated. Compatibility with old OLE implementation. */ HB_FUNC( MESSAGEBOX ) { - HB_FUNC_EXEC( WAPI_MESSAGEBOX ); + LPTSTR lpStr1 = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); + LPTSTR lpStr2 = HB_TCHAR_CONVTO( hb_parcx( 3 ) ); + HWND hWnd = ISNUM( 1 ) ? ( HWND ) ( HB_PTRUINT ) hb_parnint( 1 ) : + ( HWND ) hb_parptr( 1 ); + hb_retni( MessageBox( hWnd, lpStr1, lpStr2, hb_parni( 4 ) ) ); + HB_TCHAR_FREE( lpStr1 ); + HB_TCHAR_FREE( lpStr2 ); } - -#endif diff --git a/harbour/contrib/hbwin/win_dll.c b/harbour/contrib/hbwin/win_dll.c index aa8bc30787..2e154599f4 100644 --- a/harbour/contrib/hbwin/win_dll.c +++ b/harbour/contrib/hbwin/win_dll.c @@ -749,11 +749,68 @@ static LPVOID hb_getprocaddress( HMODULE hDLL, int iProc ) #endif } +HB_FUNC( LOADLIBRARY ) +{ + hb_retnint( ( HB_PTRDIFF ) LoadLibraryA( ( LPCSTR ) hb_parcx( 1 ) ) ); +} + +HB_FUNC( FREELIBRARY ) +{ + if( ISPOINTER( 1 ) ) + hb_retl( FreeLibrary( ( HMODULE ) hb_parptr( 1 ) ) ); + else if( ISNUM( 1 ) ) + hb_retl( FreeLibrary( ( HMODULE ) ( HB_PTRDIFF ) hb_parnint( 1 ) ) ); + else + hb_retl( FALSE ); +} + +HB_FUNC( GETPROCADDRESS ) +{ + HMODULE hDLL; + + if( HB_ISNUM( 1 ) ) + hDLL = ( HMODULE ) ( HB_PTRDIFF ) hb_parnint( 1 ); + else + hDLL = ( HMODULE ) hb_parptr( 1 ); + + hb_retptr( hDLL ? ( void * ) hb_getprocaddress( hDLL, 2 ) : NULL ); +} + #ifdef HB_COMPAT_XPP +HB_FUNC( DLLLOAD ) +{ + HB_FUNC_EXEC( LOADLIBRARY ); +} + +HB_FUNC( DLLUNLOAD ) +{ + HB_FUNC_EXEC( FREELIBRARY ); +} + +HB_FUNC( DLLCALL ) +{ + HMODULE hDLL; + + if( HB_ISPOINTER( 1 ) ) + hDLL = ( HMODULE ) hb_parptr( 1 ); + else if( HB_ISNUM( 1 ) ) + hDLL = ( HMODULE ) ( HB_PTRDIFF ) hb_parnint( 1 ); + else + hDLL = LoadLibraryA( hb_parcx( 1 ) ); + + if( hDLL && ( HB_PTRDIFF ) hDLL >= 32 ) + { + DllExec( hb_parni( 2 ), 0, hb_getprocaddress( ( HMODULE ) hDLL, 3 ), NULL, hb_pcount(), 4 ); + + if( ISCHAR( 1 ) ) + FreeLibrary( hDLL ); + } +} + HB_FUNC( DLLPREPARECALL ) { -#if !defined(HB_OS_WIN_CE) +#if ! defined(HB_OS_WIN_CE) PXPP_DLLEXEC xec = ( PXPP_DLLEXEC ) hb_gcAlloc( sizeof( XPP_DLLEXEC ), _DLLUnload ); char * pszErrorText; @@ -806,45 +863,6 @@ HB_FUNC( DLLPREPARECALL ) #endif } -HB_FUNC( DLLLOAD ) -{ - hb_retnint( ( HB_PTRDIFF ) LoadLibraryA( ( LPCSTR ) hb_parcx( 1 ) ) ) ; - -/* Proper, but incompatible version: - hb_retptr( LoadLibraryA( ( LPCSTR ) hb_parcx( 1 ) ) ) ; -*/ -} - -HB_FUNC( DLLUNLOAD ) -{ - if( ISPOINTER( 1 ) ) - hb_retl( FreeLibrary( ( HMODULE ) hb_parptr( 1 ) ) ) ; - else if( ISNUM( 1 ) ) - hb_retl( FreeLibrary( ( HMODULE ) ( HB_PTRDIFF ) hb_parnint( 1 ) ) ) ; - else - hb_retl( FALSE ); -} - -HB_FUNC( DLLCALL ) -{ - HMODULE hDLL; - - if( HB_ISPOINTER( 1 ) ) - hDLL = ( HMODULE ) hb_parptr( 1 ); - else if( HB_ISNUM( 1 ) ) - hDLL = ( HMODULE ) ( HB_PTRDIFF ) hb_parnint( 1 ); - else - hDLL = LoadLibraryA( hb_parcx( 1 ) ); - - if( hDLL && ( HB_PTRDIFF ) hDLL >= 32 ) - { - DllExec( hb_parni( 2 ), 0, hb_getprocaddress( ( HMODULE ) hDLL, 3 ), NULL, hb_pcount(), 4 ); - - if( ISCHAR( 1 ) ) - FreeLibrary( hDLL ); - } -} - HB_FUNC( DLLEXECUTECALL ) { PXPP_DLLEXEC xec = ( PXPP_DLLEXEC ) hb_parptr( 1 ); @@ -857,28 +875,6 @@ HB_FUNC( DLLEXECUTECALL ) /* ------------------------------------------------------------------ */ -HB_FUNC( LOADLIBRARY ) -{ - HB_FUNC_EXEC( DLLLOAD ); -} - -HB_FUNC( FREELIBRARY ) -{ - HB_FUNC_EXEC( DLLUNLOAD ); -} - -HB_FUNC( GETPROCADDRESS ) -{ - HMODULE hDLL; - - if( HB_ISNUM( 1 ) ) - hDLL = ( HMODULE ) ( HB_PTRDIFF ) hb_parnint( 1 ); - else - hDLL = ( HMODULE ) hb_parptr( 1 ); - - hb_retptr( hDLL ? ( void * ) hb_getprocaddress( hDLL, 2 ) : NULL ); -} - /* Call a DLL function from (x)Harbour, the first parameter is a pointer returned from GetProcAddress() above. Note that it is hardcoded to use PASCAL calling convention. */ HB_FUNC( CALLDLL ) diff --git a/harbour/contrib/hbwin/win_misc.c b/harbour/contrib/hbwin/win_misc.c index 46fe338169..0f40bfbf9e 100644 --- a/harbour/contrib/hbwin/win_misc.c +++ b/harbour/contrib/hbwin/win_misc.c @@ -227,9 +227,7 @@ HB_FUNC( WAPI_MESSAGEBOX ) { LPTSTR lpStr1 = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); LPTSTR lpStr2 = HB_TCHAR_CONVTO( hb_parcx( 3 ) ); - HWND hWnd = ISNUM( 1 ) ? ( HWND ) ( HB_PTRUINT ) hb_parnint( 1 ) : - ( HWND ) hb_parptr( 1 ); - hb_retni( MessageBox( hWnd, lpStr1, lpStr2, hb_parni( 4 ) ) ); + hb_retni( MessageBox( ( HWND ) hb_parptr( 1 ), lpStr1, lpStr2, hb_parni( 4 ) ) ); HB_TCHAR_FREE( lpStr1 ); HB_TCHAR_FREE( lpStr2 ); } @@ -249,3 +247,23 @@ HB_FUNC( WIN_WIDETOANSI ) hb_retclen_buffer( cString, strlen( cString ) ); } + +HB_FUNC( WAPI_LOADLIBRARY ) +{ + hb_retptr( LoadLibraryA( ( LPCSTR ) hb_parcx( 1 ) ) ); +} + +HB_FUNC( WAPI_FREELIBRARY ) +{ + hb_retl( FreeLibrary( ( HMODULE ) hb_parptr( 1 ) ) ); +} + +HB_FUNC( WIN_N2P ) +{ + hb_retptr( ( void * ) ( HB_PTRDIFF ) hb_parnint( 1 ) ); +} + +HB_FUNC( WIN_P2N ) +{ + hb_retnint( ( HB_PTRDIFF ) hb_parptr( 1 ) ); +}