From aa13701479d20edda1c139dcb5daee8d51ed0fb1 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 11 Dec 2009 19:21:56 +0000 Subject: [PATCH] 2009-12-11 20:16 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/wapi_winbase.c * Eliminated hb_parclen() call in WAPI_FORMATMESSAGE() function. * contrib/hbwin/win_regc.c * WIN_REGSETVALUEEX(): Adjusted casting to not drop const. ! WIN_REGSETVALUEEX(): Added support for UNICODE builds when string types (non-binary data) are passed. * contrib/hbwin/tests/testreg.prg + Extended with basic test for above. --- harbour/ChangeLog | 12 +++++++++++ harbour/contrib/hbwin/tests/testreg.prg | 1 + harbour/contrib/hbwin/wapi_winbase.c | 13 +++++++++--- harbour/contrib/hbwin/win_regc.c | 27 ++++++++++++++++++++++--- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 54d09e8af3..12466a5fc9 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,18 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-11 20:16 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbwin/wapi_winbase.c + * Eliminated hb_parclen() call in WAPI_FORMATMESSAGE() function. + + * contrib/hbwin/win_regc.c + * WIN_REGSETVALUEEX(): Adjusted casting to not drop const. + ! WIN_REGSETVALUEEX(): Added support for UNICODE builds when + string types (non-binary data) are passed. + + * contrib/hbwin/tests/testreg.prg + + Extended with basic test for above. + 2009-12-11 19:56 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/wce_smsc.c + Eliminated hb_parclen() usage. diff --git a/harbour/contrib/hbwin/tests/testreg.prg b/harbour/contrib/hbwin/tests/testreg.prg index cbdfa9671c..4a64d14b63 100644 --- a/harbour/contrib/hbwin/tests/testreg.prg +++ b/harbour/contrib/hbwin/tests/testreg.prg @@ -19,6 +19,7 @@ PROCEDURE Main() ? ">" + hb_ValToStr( win_regRead( "" ) ) + "<" ? win_regWrite( "HKCU\Control Panel\Desktop\Wallpaper", "harbour.bmp" ) + ? win_regRead( "HKCU\Control Panel\Desktop\Wallpaper" ) Inkey( 0 ) diff --git a/harbour/contrib/hbwin/wapi_winbase.c b/harbour/contrib/hbwin/wapi_winbase.c index 6513aff27f..e5c140cefb 100644 --- a/harbour/contrib/hbwin/wapi_winbase.c +++ b/harbour/contrib/hbwin/wapi_winbase.c @@ -215,17 +215,23 @@ HB_FUNC( WAPI_OUTPUTDEBUGSTRING ) HB_FUNC( WAPI_FORMATMESSAGE ) { void * hSource = NULL; + void * hBuffer; - DWORD dwBufferLen = ( DWORD ) hb_parclen( 5 ); - LPTSTR lpBuffer = dwBufferLen > 0 ? ( LPTSTR ) hb_xgrab( dwBufferLen * sizeof( TCHAR ) ) : NULL; + HB_SIZE nBufferLen; + + LPTSTR lpBuffer; DWORD dwRetVal; + ( void ) HB_PARSTR( 5, &hBuffer, &nBufferLen ); + + lpBuffer = nBufferLen > 0 ? ( LPTSTR ) hb_xgrab( nBufferLen * sizeof( TCHAR ) ) : NULL; + hb_retnl( dwRetVal = FormatMessage( ( DWORD ) hb_parnldef( 1, FORMAT_MESSAGE_FROM_SYSTEM ) /* dwFlags */, HB_ISCHAR( 2 ) ? ( LPCVOID ) HB_PARSTR( 2, &hSource, NULL ) : hb_parptr( 2 ), HB_ISNUM( 3 ) ? ( DWORD ) hb_parnl( 3 ) : GetLastError() /* dwMessageId */, ( DWORD ) hb_parnldef( 4, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ) ) /* dwLanguageId */, lpBuffer, - dwBufferLen, + ( DWORD ) nBufferLen, NULL /* TODO: Add support for this parameter. */ ) ); if( lpBuffer ) @@ -237,4 +243,5 @@ HB_FUNC( WAPI_FORMATMESSAGE ) hb_storc( NULL, 5 ); hb_strfree( hSource ); + hb_strfree( hBuffer ); } diff --git a/harbour/contrib/hbwin/win_regc.c b/harbour/contrib/hbwin/win_regc.c index 02e2bb812e..e47aa13fea 100644 --- a/harbour/contrib/hbwin/win_regc.c +++ b/harbour/contrib/hbwin/win_regc.c @@ -193,15 +193,36 @@ HB_FUNC( WIN_REGSETVALUEEX ) HB_PARSTRDEF( 2, &hKey, NULL ), 0, dwType, - ( BYTE * ) &nSpace, + ( const BYTE * ) &nSpace, sizeof( REG_DWORD ) ) == ERROR_SUCCESS ); } - else + else if( dwType == REG_SZ || + dwType == REG_EXPAND_SZ || + dwType == REG_MULTI_SZ ) + { + void * hValue; + HB_SIZE nValueLen; + LPCTSTR lpValue = HB_PARSTR( 5, &hValue, &nValueLen ); + + #if defined( UNICODE ) + nValueLen *= 2; + #endif + hb_retl( RegSetValueEx( ( HKEY ) hb_parptr( 1 ), HB_PARSTRDEF( 2, &hKey, NULL ), 0, dwType, - ( BYTE * ) hb_parcx( 5 ) /* cValue */, + ( const BYTE * ) lpValue, + ( DWORD ) nValueLen + 1 ) == ERROR_SUCCESS ); + + hb_strfree( hValue ); + } + else /* No translation for binary data */ + hb_retl( RegSetValueEx( ( HKEY ) hb_parptr( 1 ), + HB_PARSTRDEF( 2, &hKey, NULL ), + 0, + dwType, + ( const BYTE * ) hb_parc( 5 ) /* cValue */, hb_parclen( 5 ) + 1 ) == ERROR_SUCCESS ); hb_strfree( hKey );