RegSetValue()
Posted: Mon Jan 08, 2007 5:00 pm
It seems the function only stores STRING values? How can I store DWORD and BINARY values to the PPC registry?
Thanks.
Thanks.
www.FiveTechSoft.com
https://forums.fivetechsoft.com/
Code: Select all
HB_FUNC( REGSETVALUE )
{
LPWSTR pW1 = AnsiToWide( hb_parc( 2 ) );
switch( hb_itemType( hb_param( 3, HB_IT_ANY ) ) )
{
case HB_IT_STRING:
LPWSTR pW2 = AnsiToWide( hb_parc( 3 ) );
hb_retnl( RegSetValueEx( ( HKEY ) hb_parnl( 1 ), pW1, 0, REG_SZ, ( CONST BYTE * ) pW2,
( hb_parclen( 3 ) * 2 ) + 1 ) );
hb_xfree( pW2 );
break;
case HB_IT_INTEGER:
case HB_IT_LONG:
hb_retnl( RegSetValueEx( ( HKEY ) hb_parnl( 1 ), pW1, 0, REG_DWORD, ( const BYTE * ) hb_parnl( 3 ), sizeof( DWORD ) ) );
break;
}
hb_xfree( pW1 );
}
Code: Select all
//nHnd returned from RegOpenKey()
cVal := "AutoEnter"
nVal := 1
nResult := RegSetValue2( nHnd, cVal, nVal )
Code: Select all
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <item.api>
LPWSTR AnsiToWide( LPSTR );
HB_FUNC( REGSETVALUE2 )
{
LPWSTR pW1 = AnsiToWide( hb_parc( 2 ) );
LPWSTR pW2;
switch( hb_itemType( hb_param( 3, HB_IT_ANY ) ) )
{
case HB_IT_STRING:
pW2 = AnsiToWide( hb_parc( 3 ) );
hb_retnl( RegSetValueEx( ( HKEY ) hb_parnl( 1 ), pW1, 0, REG_SZ, ( CONST BYTE * ) pW2, ( hb_parclen( 3 ) * 2 ) + 1 ) );
break;
case HB_IT_INTEGER:
case HB_IT_LONG:
hb_retnl( RegSetValueEx( ( HKEY ) hb_parnl( 1 ), pW1, 0, REG_DWORD, ( const BYTE * ) hb_parnl( 3 ), sizeof( DWORD ) ) );
break;
}
hb_xfree( pW1 );
hb_xfree( pW2 );
}
#pragma ENDDUMP
Code: Select all
DWORD dwValue = hb_parnl( 3 );
...
case HB_IT_INTEGER:
case HB_IT_LONG:
hb_retnl( RegSetValueEx( ( HKEY ) hb_parnl( 1 ), pW1, 0, REG_DWORD, ( const BYTE * ) &dwValue, sizeof( DWORD ) ) );
break;