diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 73505d5e83..5f0e7b0a3d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -10,6 +10,24 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2012-11-22 19:07 UTC+0100 Viktor Szakats (harbour syenar.net) + * include/hbwinuni.h + + added HB_WINAPI_FUNCTION_NAME() macro to form a WinAPI + function name as a string (for dynamic calls) + Thanks to Mindaugas for the idea. + + * contrib/hbwin/wapi_winbase.c + * contrib/hbwin/wapi_wingdi_font.c + * contrib/hbwin/win_prn2.c + * contrib/hbwin/win_prn3.c + * contrib/hbwin/win_rpc.c + * src/rtl/diskspac.c + * src/rtl/disksphb.c + * src/rtl/fslink.c + % eliminated few UNICODE build-time branches by using + new HB_WINAPI_FUNCTION_NAME() macro + (non-UNICODE branch not tested) + 2012-11-22 18:46 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbct/doc/en/atadjust.txt * contrib/hbct/doc/en/color.txt diff --git a/harbour/contrib/hbwin/wapi_winbase.c b/harbour/contrib/hbwin/wapi_winbase.c index eb7a0ec5a1..ec71ba16c8 100644 --- a/harbour/contrib/hbwin/wapi_winbase.c +++ b/harbour/contrib/hbwin/wapi_winbase.c @@ -383,14 +383,16 @@ HB_FUNC( WAPI_GETLONGPATHNAME ) if( ! s_getPathNameAddr ) { - s_getPathNameAddr = ( _HB_GETPATHNAME ) + s_getPathNameAddr = + ( _HB_GETPATHNAME ) + GetProcAddress( #if defined( UNICODE ) - GetProcAddress( GetModuleHandle( hb_iswin9x() ? TEXT( "unicows.dll" ) : TEXT( "kernel32.dll" ) ), - "GetLongPathNameW" ); + GetModuleHandle( hb_iswin9x() ? TEXT( "unicows.dll" ) : TEXT( "kernel32.dll" ) ), #else - GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), - "GetLongPathNameA" ); + GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), #endif + HB_WINAPI_FUNCTION_NAME( "GetLongPathName" ) ); + if( ! s_getPathNameAddr ) s_getPathNameAddr = GetShortPathName; } diff --git a/harbour/contrib/hbwin/wapi_wingdi_font.c b/harbour/contrib/hbwin/wapi_wingdi_font.c index aff710f3ab..344f6cdef1 100644 --- a/harbour/contrib/hbwin/wapi_wingdi_font.c +++ b/harbour/contrib/hbwin/wapi_wingdi_font.c @@ -80,11 +80,7 @@ HB_FUNC( WAPI_ADDFONTRESOURCEEX ) if( ! s_pAddFontResourceEx ) s_pAddFontResourceEx = ( _HB_ADDFONTRESOURCEEX ) GetProcAddress( GetModuleHandle( TEXT( "gdi32.dll" ) ), -#if defined( UNICODE ) - "AddFontResourceExW" ); -#else - "AddFontResourceExA" ); -#endif + HB_WINAPI_FUNCTION_NAME( "AddFontResourceEx" ) ); if( s_pAddFontResourceEx ) { @@ -110,11 +106,7 @@ HB_FUNC( WAPI_REMOVEFONTRESOURCEEX ) if( ! s_pRemoveFontResourceEx ) s_pRemoveFontResourceEx = ( _HB_REMOVEFONTRESOURCEEX ) GetProcAddress( GetModuleHandle( TEXT( "gdi32.dll" ) ), -#if defined( UNICODE ) - "RemoveFontResourceExW" ); -#else - "RemoveFontResourceExA" ); -#endif + HB_WINAPI_FUNCTION_NAME( "RemoveFontResourceEx" ) ); if( s_pRemoveFontResourceEx ) { diff --git a/harbour/contrib/hbwin/win_prn2.c b/harbour/contrib/hbwin/win_prn2.c index 9737f47bd9..062054cbcf 100644 --- a/harbour/contrib/hbwin/win_prn2.c +++ b/harbour/contrib/hbwin/win_prn2.c @@ -137,11 +137,7 @@ static void hb_GetDefaultPrinter( PHB_ITEM pPrinterName ) if( hWinSpool ) { fnGetDefaultPrinter = ( DEFPRINTER ) GetProcAddress( hWinSpool, -#if defined( UNICODE ) - "GetDefaultPrinterW" ); -#else - "GetDefaultPrinterA" ); -#endif + HB_WINAPI_FUNCTION_NAME( "GetDefaultPrinter" ) ); if( fnGetDefaultPrinter ) { diff --git a/harbour/contrib/hbwin/win_prn3.c b/harbour/contrib/hbwin/win_prn3.c index ce45139d36..bfd90b4fdc 100644 --- a/harbour/contrib/hbwin/win_prn3.c +++ b/harbour/contrib/hbwin/win_prn3.c @@ -128,12 +128,10 @@ static HB_BOOL hb_SetDefaultPrinter( LPCTSTR lpPrinterName ) hWinSpool = hbwapi_LoadLibrarySystem( TEXT( "winspool.drv" ) ); if( ! hWinSpool ) return HB_FALSE; + fnSetDefaultPrinter = ( DEFPRINTER ) GetProcAddress( hWinSpool, -#if defined( UNICODE ) - "SetDefaultPrinterW" ); -#else - "SetDefaultPrinterA" ); -#endif + HB_WINAPI_FUNCTION_NAME( "SetDefaultPrinter" ) ); + if( ! fnSetDefaultPrinter ) { FreeLibrary( hWinSpool ); diff --git a/harbour/contrib/hbwin/win_rpc.c b/harbour/contrib/hbwin/win_rpc.c index 22195d4f91..32b9158596 100644 --- a/harbour/contrib/hbwin/win_rpc.c +++ b/harbour/contrib/hbwin/win_rpc.c @@ -78,19 +78,8 @@ HB_FUNC( WIN_UUIDCREATESTRING ) s_pUuidCreate = ( _HB_UUIDCREATE ) GetProcAddress( hRpcrt4, "UuidCreate" ); - s_pUuidToString = ( _HB_UUIDTOSTRING ) GetProcAddress( hRpcrt4, -#if defined( UNICODE ) - "UuidToStringW" ); -#else - "UuidToStringA" ); -#endif - - s_pRpcStringFree = ( _HB_RPCSTRINGFREE ) GetProcAddress( hRpcrt4, -#if defined( UNICODE ) - "RpcStringFreeW" ); -#else - "RpcStringFreeA" ); -#endif + s_pUuidToString = ( _HB_UUIDTOSTRING ) GetProcAddress( hRpcrt4, HB_WINAPI_FUNCTION_NAME( "UuidToString" ) ); + s_pRpcStringFree = ( _HB_RPCSTRINGFREE ) GetProcAddress( hRpcrt4, HB_WINAPI_FUNCTION_NAME( "RpcStringFree" ) ); } if( s_pUuidCreate && diff --git a/harbour/include/hbwinuni.h b/harbour/include/hbwinuni.h index 35cae4d16b..dab0782f65 100644 --- a/harbour/include/hbwinuni.h +++ b/harbour/include/hbwinuni.h @@ -89,6 +89,7 @@ #define HB_CHARDUPN( str, len ) hb_osStrU16EncodeN( str, len ) #define HB_OSSTRDUP( str ) hb_osStrU16Decode( str ) #define HB_OSSTRDUP2( str, buf, len ) hb_osStrU16Decode2( str, buf, len ) + #define HB_WINAPI_FUNCTION_NAME( a ) ( a "W" ) #else #define HB_PARSTR( n, h, len ) hb_parstr( n, hb_setGetOSCP(), h, len ) #define HB_PARSTRDEF( n, h, len ) hb_strnull( hb_parstr( n, hb_setGetOSCP(), h, len ) ) @@ -119,6 +120,7 @@ #define HB_CHARDUPN( str, len ) hb_osStrEncodeN( str, len ) #define HB_OSSTRDUP( str ) hb_osStrDecode( str ) #define HB_OSSTRDUP2( str, buf, len ) hb_osStrDecode2( str, buf, len ) + #define HB_WINAPI_FUNCTION_NAME( a ) ( a "A" ) #endif #endif /* HB_OS_WIN */ diff --git a/harbour/src/rtl/diskspac.c b/harbour/src/rtl/diskspac.c index 2f603894ed..24df5466b8 100644 --- a/harbour/src/rtl/diskspac.c +++ b/harbour/src/rtl/diskspac.c @@ -74,6 +74,7 @@ # endif #elif defined( HB_OS_WIN ) # include +# include "hbwinuni.h" # if defined( HB_OS_WIN_CE ) # include "hbwince.h" # endif @@ -166,14 +167,15 @@ HB_FUNC( DISKSPACE ) if( ! s_fInit ) { - s_pGetDiskFreeSpaceEx = ( P_GDFSE ) + s_pGetDiskFreeSpaceEx = + ( P_GDFSE ) + GetProcAddress( #if defined( UNICODE ) - GetProcAddress( GetModuleHandle( hb_iswin9x() ? TEXT( "unicows.dll" ) : TEXT( "kernel32.dll" ) ), - "GetDiskFreeSpaceExW" ); + GetModuleHandle( hb_iswin9x() ? TEXT( "unicows.dll" ) : TEXT( "kernel32.dll" ) ), #else - GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), - "GetDiskFreeSpaceExA" ); + GetModuleHandle( TEXT( "kernel32.dll" ) ), #endif + HB_WINAPI_FUNCTION_NAME( "GetDiskFreeSpaceEx" ) ); s_fInit = HB_TRUE; } diff --git a/harbour/src/rtl/disksphb.c b/harbour/src/rtl/disksphb.c index c751442592..276b41ffb6 100644 --- a/harbour/src/rtl/disksphb.c +++ b/harbour/src/rtl/disksphb.c @@ -126,14 +126,16 @@ HB_FUNC( HB_DISKSPACE ) if( ! s_fInit ) { - s_pGetDiskFreeSpaceEx = ( P_GDFSE ) + s_pGetDiskFreeSpaceEx = + ( P_GDFSE ) + GetProcAddress( #if defined( UNICODE ) - GetProcAddress( GetModuleHandle( hb_iswin9x() ? TEXT( "unicows.dll" ) : TEXT( "kernel32.dll" ) ), - "GetDiskFreeSpaceExW" ); + GetModuleHandle( hb_iswin9x() ? TEXT( "unicows.dll" ) : TEXT( "kernel32.dll" ) ), #else - GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), - "GetDiskFreeSpaceExA" ); + GetModuleHandle( TEXT( "kernel32.dll" ) ), #endif + HB_WINAPI_FUNCTION_NAME( "GetDiskFreeSpaceEx" ) ); + s_fInit = HB_TRUE; } diff --git a/harbour/src/rtl/fslink.c b/harbour/src/rtl/fslink.c index 3987f3eaf5..4a36949db9 100644 --- a/harbour/src/rtl/fslink.c +++ b/harbour/src/rtl/fslink.c @@ -79,12 +79,10 @@ HB_BOOL hb_fsLink( const char * pszExisting, const char * pszNewFile ) static _HB_CREATEHARDLINK s_pCreateHardLink = NULL; if( ! s_pCreateHardLink ) - s_pCreateHardLink = ( _HB_CREATEHARDLINK ) GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), -#if defined( UNICODE ) - "CreateHardLinkW" ); -#else - "CreateHardLinkA" ); -#endif + s_pCreateHardLink = + ( _HB_CREATEHARDLINK ) + GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), + HB_WINAPI_FUNCTION_NAME( "CreateHardLink" ) ); if( s_pCreateHardLink ) { @@ -163,12 +161,10 @@ HB_BOOL hb_fsLinkSym( const char * pszTarget, const char * pszNewFile ) #endif if( ! s_pCreateSymbolicLink ) - s_pCreateSymbolicLink = ( _HB_CREATESYMBOLICLINK ) GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), -#if defined( UNICODE ) - "CreateSymbolicLinkW" ); -#else - "CreateSymbolicLinkA" ); -#endif + s_pCreateSymbolicLink = + ( _HB_CREATESYMBOLICLINK ) + GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), + HB_WINAPI_FUNCTION_NAME( "CreateSymbolicLink" ) ); if( s_pCreateSymbolicLink ) { @@ -269,12 +265,10 @@ char * hb_fsLinkRead( const char * pszFile ) #endif if( ! s_pGetFinalPathNameByHandle ) - s_pGetFinalPathNameByHandle = ( _HB_GETFINALPATHNAMEBYHANDLE ) GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), -#if defined( UNICODE ) - "GetFinalPathNameByHandleW" ); -#else - "GetFinalPathNameByHandleA" ); -#endif + s_pGetFinalPathNameByHandle = + ( _HB_GETFINALPATHNAMEBYHANDLE ) + GetProcAddress( GetModuleHandle( TEXT( "kernel32.dll" ) ), + HB_WINAPI_FUNCTION_NAME( "GetFinalPathNameByHandle" ) ); if( s_pGetFinalPathNameByHandle ) {