From 2551351908ba205a2659e4ef39b9cee9513e7cce Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 9 Dec 2009 14:45:54 +0000 Subject: [PATCH] 2009-12-09 15:41 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbwin/win_regc.c * contrib/hbwin/win_prn3.c * contrib/hbwin/win_dll.c + Using new UNICODE parameter passing macros instead of HB_TCHAR*() ones. ; Please review me. The transition is not yet full, as there were some problematic cases, which I've left as is. ! Added UNICODE support for WIN_REGQUERYVALUEEX()'s string return values. * contrib/hbwin/tests/testreg.prg + Added one more test call. ! Fixed to not use legacy registry call. --- harbour/ChangeLog | 13 ++++++ harbour/contrib/hbwin/tests/testreg.prg | 3 +- harbour/contrib/hbwin/win_dll.c | 21 ++++----- harbour/contrib/hbwin/win_prn3.c | 7 +-- harbour/contrib/hbwin/win_regc.c | 61 +++++++++++++++++-------- 5 files changed, 71 insertions(+), 34 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 8a7780c2f0..7705577b48 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,19 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-09 15:41 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbwin/win_regc.c + * contrib/hbwin/win_prn3.c + * contrib/hbwin/win_dll.c + + Using new UNICODE parameter passing macros instead of HB_TCHAR*() ones. + ; Please review me. The transition is not yet full, as there were + some problematic cases, which I've left as is. + ! Added UNICODE support for WIN_REGQUERYVALUEEX()'s string return values. + + * contrib/hbwin/tests/testreg.prg + + Added one more test call. + ! Fixed to not use legacy registry call. + 2009-12-09 15:30 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapilng.h + harbour/include/hbmsgreg.h diff --git a/harbour/contrib/hbwin/tests/testreg.prg b/harbour/contrib/hbwin/tests/testreg.prg index 3185137f71..cbdfa9671c 100644 --- a/harbour/contrib/hbwin/tests/testreg.prg +++ b/harbour/contrib/hbwin/tests/testreg.prg @@ -11,9 +11,10 @@ PROCEDURE Main() ? ">" + wapi_GetCommandLine() + "<" /* old API */ - ? ">" + hb_ValToStr( GetRegistry( HKEY_CURRENT_USER, "Control Panel\Desktop", "Wallpaper" ) ) + "<" + ? ">" + hb_ValToStr( win_regGet( HKEY_CURRENT_USER, "Control Panel\Desktop", "Wallpaper" ) ) + "<" /* new API */ + ? ">" + hb_ValToStr( win_regRead( "HKCU\Environment\PATH" ) ) + "<" ? ">" + hb_ValToStr( tmp := win_regRead( "HKCU\Control Panel\Desktop\Wallpaper" ) ) + "<" ? ">" + hb_ValToStr( win_regRead( "" ) ) + "<" diff --git a/harbour/contrib/hbwin/win_dll.c b/harbour/contrib/hbwin/win_dll.c index c9432db32c..a12c892713 100644 --- a/harbour/contrib/hbwin/win_dll.c +++ b/harbour/contrib/hbwin/win_dll.c @@ -64,6 +64,7 @@ #include "hbapi.h" #include "hbapierr.h" #include "hbapiitm.h" +#include "hbwinuni.h" #if !defined( HB_NO_ASM ) && defined( HB_OS_WIN ) && !defined( __CYGWIN__ ) @@ -660,11 +661,11 @@ static LPVOID hb_getprocaddress( HMODULE hDLL, int iProc ) HB_FUNC( LOADLIBRARY ) { - LPTSTR lpName = HB_TCHAR_CONVTO( hb_parcx( 1 ) ); + void * hName; - hb_retnint( ( HB_PTRDIFF ) LoadLibrary( lpName ) ); + hb_retnint( ( HB_PTRDIFF ) LoadLibrary( ( LPCTSTR ) HB_PARSTRDEF( 1, &hName, NULL ) ) ); - HB_TCHAR_FREE( lpName ); + hb_strfree( hName ); } HB_FUNC( FREELIBRARY ) @@ -711,11 +712,9 @@ HB_FUNC( DLLCALL ) hDLL = ( HMODULE ) ( HB_PTRDIFF ) hb_parnint( 1 ); else { - LPTSTR lpName = HB_TCHAR_CONVTO( hb_parcx( 1 ) ); - - hDLL = LoadLibrary( lpName ); - - HB_TCHAR_FREE( lpName ); + void * hName; + hDLL = LoadLibrary( ( LPCTSTR ) HB_PARSTRDEF( 1, &hName, NULL ) ); + hb_strfree( hName ); } if( hDLL && ( HB_PTRDIFF ) hDLL >= 32 ) @@ -739,9 +738,9 @@ HB_FUNC( DLLPREPARECALL ) if( HB_ISCHAR( 1 ) ) { - LPTSTR lpName = HB_TCHAR_CONVTO( hb_parc( 1 ) ); - xec->hDLL = LoadLibrary( lpName ); - HB_TCHAR_FREE( lpName ); + void * hName; + xec->hDLL = LoadLibrary( ( LPCTSTR ) HB_PARSTRDEF( 1, &hName, NULL ) ); + hb_strfree( hName ); } else if( HB_ISPOINTER( 1 ) ) xec->hDLL = ( HMODULE ) hb_parptr( 1 ); diff --git a/harbour/contrib/hbwin/win_prn3.c b/harbour/contrib/hbwin/win_prn3.c index 9670ce0a17..3aeeff6737 100644 --- a/harbour/contrib/hbwin/win_prn3.c +++ b/harbour/contrib/hbwin/win_prn3.c @@ -64,6 +64,7 @@ #define HB_OS_WIN_USED #include "hbapi.h" +#include "hbwinuni.h" static HB_BOOL hb_SetDefaultPrinter( LPTSTR lpPrinterName ) { @@ -251,11 +252,11 @@ HB_FUNC( WIN_PRINTERSETDEFAULT ) { if( hb_parclen( 1 ) > 0 ) { - LPTSTR lpPrinterName = HB_TCHAR_CONVTO( hb_parc( 1 ) ); + void * hPrinterName; - hb_retl( hb_SetDefaultPrinter( lpPrinterName ) ); + hb_retl( hb_SetDefaultPrinter( ( LPTSTR ) HB_PARSTR( 1, &hPrinterName, NULL ) ) ); - HB_TCHAR_FREE( lpPrinterName ); + hb_strfree( hPrinterName ); } else hb_retl( HB_FALSE ); diff --git a/harbour/contrib/hbwin/win_regc.c b/harbour/contrib/hbwin/win_regc.c index 92d013b099..9260991ef0 100644 --- a/harbour/contrib/hbwin/win_regc.c +++ b/harbour/contrib/hbwin/win_regc.c @@ -54,6 +54,7 @@ #include "hbapi.h" #include "hbapiitm.h" +#include "hbwinuni.h" static HKEY hb_regkeyconv( HB_PTRUINT nKey ) { @@ -80,12 +81,12 @@ static HKEY hb_regkeyconv( HB_PTRUINT nKey ) HB_FUNC( WIN_REGCREATEKEYEX ) { - LPTSTR lpText = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); + void * hKey; HKEY hkResult = NULL; DWORD dwDisposition = 0; hb_retl( RegCreateKeyEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), - lpText, + ( LPCTSTR ) HB_PARSTRDEF( 2, &hKey, NULL ), 0, NULL, hb_parnl( 5 ) /* dwOptions */, @@ -97,23 +98,23 @@ HB_FUNC( WIN_REGCREATEKEYEX ) hb_storptr( hkResult, 8 ); hb_stornl( dwDisposition, 9 ); - HB_TCHAR_FREE( lpText ); + hb_strfree( hKey ); } HB_FUNC( WIN_REGOPENKEYEX ) { - LPTSTR lpText = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); + void * hKey; HKEY hkResult = NULL; hb_retl( RegOpenKeyEx( hb_regkeyconv( ( HB_PTRUINT ) hb_parnint( 1 ) ), - lpText, + ( LPCTSTR ) HB_PARSTRDEF( 2, &hKey, NULL ), 0 /* dwOptions */, hb_parnl( 4 ) /* samDesired */, &hkResult ) == ERROR_SUCCESS ); hb_storptr( hkResult, 5 ); - HB_TCHAR_FREE( lpText ); + hb_strfree( hKey ); } HB_FUNC( WIN_REGQUERYVALUEEX ) @@ -131,17 +132,39 @@ HB_FUNC( WIN_REGQUERYVALUEEX ) { if( dwSize > 0 ) { - BYTE * cValue = ( BYTE * ) hb_xgrab( dwSize + 1 ); + if( dwType == REG_SZ || dwType == REG_EXPAND_SZ || dwType == REG_MULTI_SZ ) + { + LPTSTR lpValue = ( LPTSTR ) hb_xgrab( ( dwSize + 1 ) * sizeof( TCHAR ) ); - RegQueryValueEx( ( HKEY ) hb_parptr( 1 ), - lpKey, - NULL, - &dwType, - ( BYTE * ) cValue, - &dwSize ); + RegQueryValueEx( ( HKEY ) hb_parptr( 1 ), + lpKey, + NULL, + &dwType, + ( LPBYTE ) lpValue, + &dwSize ); - if( ! hb_storclen_buffer( ( char * ) cValue, dwSize, 5 ) ) - hb_xfree( cValue ); + #if defined( UNICODE ) + dwSize >>= 1; + #endif + + HB_STORSTRLEN( lpValue, dwSize, 5 ); + + hb_xfree( lpValue ); + } + else /* No translation for binary data */ + { + BYTE * cValue = ( BYTE * ) hb_xgrab( dwSize + 1 ); + + RegQueryValueEx( ( HKEY ) hb_parptr( 1 ), + lpKey, + NULL, + &dwType, + ( LPBYTE ) cValue, + &dwSize ); + + if( ! hb_storclen_buffer( ( char * ) cValue, dwSize, 5 ) ) + hb_xfree( cValue ); + } } else hb_storc( NULL, 5 ); @@ -157,14 +180,14 @@ HB_FUNC( WIN_REGQUERYVALUEEX ) HB_FUNC( WIN_REGSETVALUEEX ) { - LPTSTR lpKey = HB_TCHAR_CONVTO( hb_parcx( 2 ) ); + void * hKey; DWORD dwType = ( DWORD ) hb_parnl( 4 ); if( dwType == REG_DWORD ) { DWORD nSpace = ( DWORD ) hb_parnl( 5 ); hb_retl( RegSetValueEx( ( HKEY ) hb_parptr( 1 ), - lpKey, + ( LPCTSTR ) HB_PARSTRDEF( 2, &hKey, NULL ), 0, dwType, ( BYTE * ) &nSpace, @@ -172,13 +195,13 @@ HB_FUNC( WIN_REGSETVALUEEX ) } else hb_retl( RegSetValueEx( ( HKEY ) hb_parptr( 1 ), - lpKey, + ( LPCTSTR ) HB_PARSTRDEF( 2, &hKey, NULL ), 0, dwType, ( BYTE * ) hb_parcx( 5 ) /* cValue */, hb_parclen( 5 ) + 1 ) == ERROR_SUCCESS ); - HB_TCHAR_FREE( lpKey ); + hb_strfree( hKey ); } HB_FUNC( WIN_REGCLOSEKEY )