diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2d7800528d..47b0131c76 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,10 +17,33 @@ past entries belonging to these authors: Viktor Szakats. */ +2009-05-19 07:20 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + * contrib/hbwin/win_reg.prg + * contrib/hbwin/win_regc.c + * Cleanups: Documenting params, changing default, using SWITCH, + HKEY to HKCU (from HKLM) to be friendly with restricted user + situations (code may become incompatible), removed unused params, + changed return values to logical, more consistently filling params + returned by ref, fixed hkResult usage, fixed hbResult to use real + pointer type, minor opts. + Some of these changes may create incompatibility if: + - no hkey is passed, since the default has changed. + - using win_reg*() functions directly, since return value and + hbResult type has changed. + ! Fixed potential GPF is non-string was passed for string params. + + * contrib/hbwin/tests/testreg.prg + + Added registry write test. + + * utils/hbmk2/hbmk2.prg + * utils/hbi18n/hbi18n.prg + * utils/hbrun/hbrun.prg + * Minor opt. + 2009-05-18 14:26 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * harbour/contrib/gtwvg/wvgsink.c * harbour/contrib/gtwvg/wvgax.c - ! Fixes to newer OLE implementation. + ! Fixes to newer OLE implementation. Thanks to Mindaugus and Przemek for doing all the spadework. Now I can receive events as was doing before, fantastic. diff --git a/harbour/contrib/hbwin/tests/testreg.prg b/harbour/contrib/hbwin/tests/testreg.prg index 8fa0023ac5..3185137f71 100644 --- a/harbour/contrib/hbwin/tests/testreg.prg +++ b/harbour/contrib/hbwin/tests/testreg.prg @@ -5,6 +5,7 @@ #include "hbwin.ch" PROCEDURE Main() + LOCAL tmp ? ">" + win_GetCommandLineParam() + "<" ? ">" + wapi_GetCommandLine() + "<" @@ -13,9 +14,13 @@ PROCEDURE Main() ? ">" + hb_ValToStr( GetRegistry( HKEY_CURRENT_USER, "Control Panel\Desktop", "Wallpaper" ) ) + "<" /* new API */ - ? ">" + hb_ValToStr( win_regRead( "HKCU\Control Panel\Desktop\Wallpaper" ) ) + "<" + ? ">" + hb_ValToStr( tmp := win_regRead( "HKCU\Control Panel\Desktop\Wallpaper" ) ) + "<" ? ">" + hb_ValToStr( win_regRead( "" ) ) + "<" -// ? win_regWrite( "HKCU\Control Panel\Desktop\Wallpaper", "harbour.bmp" ) + ? win_regWrite( "HKCU\Control Panel\Desktop\Wallpaper", "harbour.bmp" ) + + Inkey( 0 ) + + ? win_regWrite( "HKCU\Control Panel\Desktop\Wallpaper", tmp ) RETURN diff --git a/harbour/contrib/hbwin/win_reg.prg b/harbour/contrib/hbwin/win_reg.prg index fd51c8c606..80949d3559 100644 --- a/harbour/contrib/hbwin/win_reg.prg +++ b/harbour/contrib/hbwin/win_reg.prg @@ -6,7 +6,7 @@ * Harbour Project source code: * Windows registry API * - * Copyright 2008 Viktor Szakats + * Copyright 2008-2009 Viktor Szakats * Copyright 2004 Peter Rees * Rees Software & Systems Ltd * www - http://www.harbour-project.org @@ -56,8 +56,7 @@ /* ------------------------------------------------------------------- */ -/* Usage: win_regPathSplit( cRegPath, @nHKEY, @cKey, @cEntry ) */ -PROCEDURE win_regPathSplit( cRegPath, nHKEY, cKey, cEntry ) +PROCEDURE win_regPathSplit( cRegPath, /* @ */ nHKEY, /* @ */ cKey, /* @ */ cEntry ) LOCAL cHKEY LOCAL tmp @@ -136,13 +135,11 @@ FUNCTION win_regWrite( cRegPath, xValue ) #define REG_FULL_RESOURCE_DESCRIPTOR 9 // Resource list in the hardware description #define REG_RESOURCE_REQUIREMENTS_LIST 10 -#define ERROR_SUCCESS 0 - -FUNCTION QueryRegistry( nHKEYHandle, cKeyName, cEntryName, xValue, lSetIt ) - LOCAL xKey := GetRegistry( nHKEYHandle, cKeyName, cEntryName ) +FUNCTION QueryRegistry( nHKEY, cKeyName, cEntryName, xValue, lSetIt ) + LOCAL xKey := GetRegistry( nHKEY, cKeyName, cEntryName ) LOCAL cValType := ValType( xValue ) - LOCAL rVal + LOCAL lRetVal DEFAULT lSetIT TO .F. @@ -154,25 +151,22 @@ FUNCTION QueryRegistry( nHKEYHandle, cKeyName, cEntryName, xValue, lSetIt ) cValType := ValType( xValue ) ENDIF - rVal := ( xKey != NIL .AND. xValue != NIL .AND. cValType == ValType( xKey ) .AND. xValue == xKey ) - IF ! rVal .AND. lSetIt - rVal := SetRegistry( nHKEYHandle, cKeyName, cEntryName, xValue ) + lRetVal := ( xKey != NIL .AND. xValue != NIL .AND. cValType == ValType( xKey ) .AND. xValue == xKey ) + IF ! lRetVal .AND. lSetIt + lRetVal := SetRegistry( nHKEY, cKeyName, cEntryName, xValue ) ENDIF - RETURN rVal + RETURN lRetVal -FUNCTION GetRegistry( nHKEYHandle, cKeyName, cEntryName, xDefault ) +FUNCTION GetRegistry( nHKEY, cKeyName, cEntryName, xDefault ) LOCAL xRetVal := xDefault - LOCAL nKeyHandle := 0 + LOCAL pKeyHandle LOCAL nValueType - DEFAULT nHKeyHandle TO 0 + IF win_RegOpenKeyEx( nHKEY, cKeyName, 0, KEY_QUERY_VALUE, @pKeyHandle ) - IF win_RegOpenKeyEx( nHKEYHandle, cKeyName, 0, KEY_QUERY_VALUE, @nKeyHandle ) == ERROR_SUCCESS - - nValueType := 0 /* retrieve the length of the value */ - IF win_RegQueryValueEx( nKeyHandle, cEntryName, 0, @nValueType, @xRetVal ) > 0 + IF win_RegQueryValueEx( pKeyHandle, cEntryName, 0, @nValueType, @xRetVal ) > 0 IF nValueType == REG_DWORD .OR. ; nValueType == REG_DWORD_LITTLE_ENDIAN .OR. ; @@ -184,46 +178,45 @@ FUNCTION GetRegistry( nHKEYHandle, cKeyName, cEntryName, xDefault ) ENDIF ENDIF - win_RegCloseKey( nKeyHandle ) + win_RegCloseKey( pKeyHandle ) ENDIF RETURN xRetVal -FUNCTION SetRegistry( nHKEYHandle, cKeyName, cEntryName, xValue ) +FUNCTION SetRegistry( nHKEY, cKeyName, cEntryName, xValue ) LOCAL cName LOCAL nValueType - LOCAL rVal := .F. - LOCAL cType - LOCAL nKeyHandle := 0 - LOCAL nResult := 1 + LOCAL lRetVal := .F. + LOCAL pKeyHandle - DEFAULT nHKeyHandle TO 0 - - IF win_RegCreateKeyEx( nHKEYHandle, cKeyName, 0, 0, 0, KEY_SET_VALUE, 0, @nKeyHandle, @nResult ) == ERROR_SUCCESS + IF win_RegCreateKeyEx( nHKEY, cKeyName, 0, 0, 0, KEY_SET_VALUE, 0, @pKeyHandle ) /* no support for Arrays, Codeblock ... */ - cType := ValType( xValue ) - - DO CASE - CASE cType == "L" + SWITCH ValType( xValue ) + CASE "L" nValueType := REG_DWORD cName := iif( xValue, 1, 0 ) - CASE cType == "D" + EXIT + CASE "D" nValueType := REG_SZ cName := DToS( xValue ) - CASE cType == "N" + EXIT + CASE "N" nValueType := REG_DWORD cName := xValue - CASE cType $ "CM" + EXIT + CASE "C" + CASE "M" nValueType := REG_SZ cName := xValue - ENDCASE + EXIT + ENDSWITCH IF cName != NIL - rVal := ( win_RegSetValueEx( nKeyHandle, cEntryName, 0, nValueType, cName ) == ERROR_SUCCESS ) + lRetVal := win_RegSetValueEx( pKeyHandle, cEntryName, 0, nValueType, cName ) ENDIF - win_RegCloseKey( nKeyHandle ) + win_RegCloseKey( pKeyHandle ) ENDIF - RETURN rVal + RETURN lRetVal diff --git a/harbour/contrib/hbwin/win_regc.c b/harbour/contrib/hbwin/win_regc.c index 6e5669db82..ba6746de69 100644 --- a/harbour/contrib/hbwin/win_regc.c +++ b/harbour/contrib/hbwin/win_regc.c @@ -5,8 +5,9 @@ /* * Harbour Project source code: * - * Copyright 2004 Peter Rees - * Rees Software & Systems Ltd + * Copyright 2008-2009 Viktor Szakats + * Copyright 2004 Peter Rees + * Rees Software & Systems Ltd * * www - http://www.harbour-project.org * @@ -61,13 +62,13 @@ static HKEY hb_regkeyconv( HB_PTRUINT nKey ) { case 1: return ( HKEY ) HKEY_CLASSES_ROOT; + case 0: case 2: return ( HKEY ) HKEY_CURRENT_USER; #if ! defined( HB_OS_WIN_CE ) case 3: return ( HKEY ) HKEY_CURRENT_CONFIG; #endif - case 0: case 4: return ( HKEY ) HKEY_LOCAL_MACHINE; case 5: @@ -79,58 +80,49 @@ static HKEY hb_regkeyconv( HB_PTRUINT nKey ) HB_FUNC( WIN_REGCREATEKEYEX ) { - HKEY hWnd = ( HKEY ) ( HB_PTRUINT ) hb_parnint( 8 ); - ULONG nResult = hb_parnl( 9 ); - LPTSTR lpText = HB_TCHAR_CONVTO( hb_parc( 2 ) ); + LPTSTR lpText = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); + HKEY hkResult = NULL; + DWORD dwDisposition = 0; - if( RegCreateKeyEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), - lpText, - 0, - NULL, - hb_parnl( 5 ), - hb_parnl( 6 ), - NULL, - &hWnd, - &nResult ) == ERROR_SUCCESS ) - { - hb_stornint( ( HB_PTRUINT ) hWnd, 8 ); - hb_stornl( nResult, 9 ); + hb_retl( RegCreateKeyEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), + lpText, + 0, + NULL, + hb_parnl( 5 ) /* dwOptions */, + hb_parnl( 6 ) /* samDesired */, + NULL /* lpSecurityAttributes */, + &hkResult, + &dwDisposition ) == ERROR_SUCCESS ); - hb_retnl( ERROR_SUCCESS ); - } - else - hb_retnl( -1 ); + hb_storptr( hkResult, 8 ); + hb_stornl( dwDisposition, 9 ); HB_TCHAR_FREE( lpText ); } HB_FUNC( WIN_REGOPENKEYEX ) { - HKEY hWnd; - LPTSTR lpText = HB_TCHAR_CONVTO( hb_parc( 2 ) ); + LPTSTR lpText = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); + HKEY hkResult = NULL; - if( RegOpenKeyEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), - lpText, - 0, - hb_parnl( 4 ), - &hWnd ) == ERROR_SUCCESS ) - { - hb_stornint( ( HB_PTRUINT ) hWnd, 5 ); - hb_retnl( ERROR_SUCCESS ); - } - else - hb_retnl( -1 ); + hb_retl( RegOpenKeyEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), + lpText, + 0 /* dwOptions */, + hb_parnl( 4 ) /* samDesired */, + &hkResult ) == ERROR_SUCCESS ); + + hb_storptr( hkResult, 5 ); HB_TCHAR_FREE( lpText ); } HB_FUNC( WIN_REGQUERYVALUEEX ) { + LPTSTR lpKey = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); DWORD nType = 0; DWORD nSize = 0; - LPTSTR lpKey = HB_TCHAR_CONVTO( hb_parc( 2 ) ); - if( RegQueryValueEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), + if( RegQueryValueEx( ( HKEY ) hb_parptr( 1 ), lpKey, NULL, &nType, @@ -141,48 +133,47 @@ HB_FUNC( WIN_REGQUERYVALUEEX ) { BYTE * cValue = ( BYTE * ) hb_xgrab( nSize + 1 ); - RegQueryValueEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), + RegQueryValueEx( ( HKEY ) hb_parptr( 1 ), lpKey, NULL, &nType, ( BYTE * ) cValue, &nSize ); - hb_stornl( nType, 4 ); - if( ! hb_storclen_buffer( ( char * ) cValue, nSize, 5 ) ) hb_xfree( cValue ); } } - HB_TCHAR_FREE( lpKey ); + hb_stornl( nType, 4 ); hb_retnl( nSize ); + + HB_TCHAR_FREE( lpKey ); } HB_FUNC( WIN_REGSETVALUEEX ) { + LPTSTR lpKey = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); DWORD nType = ( DWORD ) hb_parnl( 4 ); - LPTSTR lpKey = HB_TCHAR_CONVTO( hb_parc( 2 ) ); - if( nType != REG_DWORD ) + if( nType == REG_DWORD ) { - BYTE * cValue = ( BYTE * ) hb_parc( 5 ); - hb_retni( RegSetValueEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), - lpKey, - 0, - nType, - ( BYTE * ) cValue, - hb_parclen( 5 ) + 1 ) ); + DWORD nSpace = ( DWORD ) hb_parnl( 5 ); + hb_retl( RegSetValueEx( ( HKEY ) hb_parptr( 1 ), + lpKey, + 0, + nType, + ( BYTE * ) &nSpace, + sizeof( REG_DWORD ) ) == ERROR_SUCCESS ); } else { - DWORD nSpace = ( DWORD ) hb_parnl( 5 ); - hb_retni( RegSetValueEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), - lpKey, - 0, - nType, - ( BYTE * ) &nSpace, - sizeof( REG_DWORD ) ) ); + hb_retl( RegSetValueEx( ( HKEY ) hb_parptr( 1 ), + lpKey, + 0, + nType, + ( BYTE * ) hb_parcx( 5 ) /* cValue */, + hb_parclen( 5 ) + 1 ) == ERROR_SUCCESS ); } HB_TCHAR_FREE( lpKey ); @@ -190,5 +181,5 @@ HB_FUNC( WIN_REGSETVALUEEX ) HB_FUNC( WIN_REGCLOSEKEY ) { - hb_retnl( RegCloseKey( ( HKEY ) ( HB_PTRUINT ) hb_parnint( 1 ) ) ); + hb_retl( RegCloseKey( ( HKEY ) hb_parptr( 1 ) ) == ERROR_SUCCESS ); } diff --git a/harbour/utils/hbi18n/hbi18n.prg b/harbour/utils/hbi18n/hbi18n.prg index 9dbd08bf49..03b69a321e 100644 --- a/harbour/utils/hbi18n/hbi18n.prg +++ b/harbour/utils/hbi18n/hbi18n.prg @@ -150,7 +150,7 @@ PROCEDURE Main( ... ) STATIC FUNCTION HBRawVersion() - RETURN StrTran( Version(), "Harbour ", "" ) + RETURN StrTran( Version(), "Harbour " ) STATIC PROCEDURE Logo() diff --git a/harbour/utils/hbmk2/hbmk2.prg b/harbour/utils/hbmk2/hbmk2.prg index 50b86a8555..3e7a73b330 100644 --- a/harbour/utils/hbmk2/hbmk2.prg +++ b/harbour/utils/hbmk2/hbmk2.prg @@ -3048,7 +3048,7 @@ FUNCTION hbmk( aArgs, /* @ */ lPause ) IF "{SCRIPT}" $ cOpt_Res fhnd := hb_FTempCreateEx( @cScriptFile, NIL, NIL, ".lnk" ) IF fhnd != F_ERROR - FWrite( fhnd, StrTran( cOpt_Res, "{SCRIPT}", "" ) ) + FWrite( fhnd, StrTran( cOpt_Res, "{SCRIPT}" ) ) FClose( fhnd ) cOpt_Res := "@" + cScriptFile ELSE @@ -3169,7 +3169,7 @@ FUNCTION hbmk( aArgs, /* @ */ lPause ) IF "{SCRIPT}" $ cOpt_CompCLoop fhnd := hb_FTempCreateEx( @cScriptFile, NIL, NIL, ".cpl" ) IF fhnd != F_ERROR - FWrite( fhnd, StrTran( cOpt_CompCLoop, "{SCRIPT}", "" ) ) + FWrite( fhnd, StrTran( cOpt_CompCLoop, "{SCRIPT}" ) ) FClose( fhnd ) cOpt_CompCLoop := "@" + cScriptFile ELSE @@ -3310,7 +3310,7 @@ FUNCTION hbmk( aArgs, /* @ */ lPause ) IF "{SCRIPT}" $ cOpt_Link fhnd := hb_FTempCreateEx( @cScriptFile, NIL, NIL, ".lnk" ) IF fhnd != F_ERROR - FWrite( fhnd, StrTran( cOpt_Link, "{SCRIPT}", "" ) ) + FWrite( fhnd, StrTran( cOpt_Link, "{SCRIPT}" ) ) FClose( fhnd ) cOpt_Link := "@" + cScriptFile ELSE @@ -3365,7 +3365,7 @@ FUNCTION hbmk( aArgs, /* @ */ lPause ) IF "{SCRIPT}" $ cOpt_Lib fhnd := hb_FTempCreateEx( @cScriptFile, NIL, NIL, ".lnk" ) IF fhnd != F_ERROR - FWrite( fhnd, StrTran( cOpt_Lib, "{SCRIPT}", "" ) ) + FWrite( fhnd, StrTran( cOpt_Lib, "{SCRIPT}" ) ) FClose( fhnd ) cOpt_Lib := "@" + cScriptFile ELSE @@ -3422,7 +3422,7 @@ FUNCTION hbmk( aArgs, /* @ */ lPause ) IF "{SCRIPT}" $ cOpt_Dyn fhnd := hb_FTempCreateEx( @cScriptFile, NIL, NIL, ".lnk" ) IF fhnd != F_ERROR - FWrite( fhnd, StrTran( cOpt_Dyn, "{SCRIPT}", "" ) ) + FWrite( fhnd, StrTran( cOpt_Dyn, "{SCRIPT}" ) ) FClose( fhnd ) cOpt_Dyn := "@" + cScriptFile ELSE @@ -5500,7 +5500,7 @@ STATIC FUNCTION VCSID( cDir, cVCSHEAD, /* @ */ cType ) tmp := At( Chr( 10 ), cStdOut ) IF tmp > 0 cStdOut := Left( cStdOut, tmp - 1 ) - cResult := hb_ntos( Val( AllTrim( StrTran( cStdOut, '"', "" ) ) ) + 1 ) + cResult := hb_ntos( Val( AllTrim( StrTran( cStdOut, '"' ) ) ) + 1 ) ENDIF ENDIF ENDSWITCH @@ -5520,15 +5520,15 @@ STATIC FUNCTION VCSID( cDir, cVCSHEAD, /* @ */ cType ) /* 10959 */ CASE _VCS_GIT /* fe3bb56 */ - cStdOut := StrTran( cStdOut, Chr( 13 ), "" ) - cResult := StrTran( cStdOut, Chr( 10 ), "" ) + cStdOut := StrTran( cStdOut, Chr( 13 ) ) + cResult := StrTran( cStdOut, Chr( 10 ) ) EXIT CASE _VCS_MERCURIAL /* changeset: 696:9e33729cafae... */ tmp := At( Chr( 10 ), cStdOut ) IF tmp > 0 cStdOut := Left( cStdOut, tmp - 1 ) - cResult := AllTrim( StrTran( cStdOut, "changeset:", "" ) ) + cResult := AllTrim( StrTran( cStdOut, "changeset:" ) ) ENDIF EXIT ENDSWITCH @@ -5645,7 +5645,7 @@ STATIC PROCEDURE ShowHeader( hbmk ) RETURN STATIC FUNCTION HBRawVersion() - RETURN StrTran( Version(), "Harbour ", "" ) + RETURN StrTran( Version(), "Harbour " ) STATIC PROCEDURE ShowHelp( lLong ) diff --git a/harbour/utils/hbrun/hbrun.prg b/harbour/utils/hbrun/hbrun.prg index da517984d2..91320b5827 100644 --- a/harbour/utils/hbrun/hbrun.prg +++ b/harbour/utils/hbrun/hbrun.prg @@ -319,6 +319,6 @@ STATIC PROCEDURE HB_DotExec( cCommand ) RETURN STATIC FUNCTION HBRawVersion() - RETURN StrTran( Version(), "Harbour ", "" ) + RETURN StrTran( Version(), "Harbour " ) /* ********************************************************************** */