RegSetValue()
-
- Posts: 42
- Joined: Wed Oct 26, 2005 1:20 pm
- Location: Marshall, Virginia, USA
- Contact:
RegSetValue()
It seems the function only stores STRING values? How can I store DWORD and BINARY values to the PPC registry?
Thanks.
Thanks.
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
Merchant Software Corp
Marshall, Virginia USA
- Antonio Linares
- Site Admin
- Posts: 42611
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 49 times
- Been thanked: 88 times
- Contact:
-
- Posts: 42
- Joined: Wed Oct 26, 2005 1:20 pm
- Location: Marshall, Virginia, USA
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42611
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 49 times
- Been thanked: 88 times
- Contact:
Bill,
This one should work for strings and numbers (not decimals):
For binary values we may need to supply a fourth parameter to the function to specify the type, as there is no a Clipper type that may represent binary.
This one should work for strings and numbers (not decimals):
Code: Select all | Expand
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 );}
For binary values we may need to supply a fourth parameter to the function to specify the type, as there is no a Clipper type that may represent binary.
-
- Posts: 42
- Joined: Wed Oct 26, 2005 1:20 pm
- Location: Marshall, Virginia, USA
- Contact:
Hi Antonio,
Thanks for the efforts. However, I have tried to set a DWORD value but receive a return value of 87, which is "INVALID PARAMETER" and the value is not added to the registry.
Here is a sample of my call to it:
Also, I had to change your code slightly as the compiler complained about pW2 being declared within the CASE. Here is revised:
Thanks for the efforts. However, I have tried to set a DWORD value but receive a return value of 87, which is "INVALID PARAMETER" and the value is not added to the registry.
Here is a sample of my call to it:
Code: Select all | Expand
//nHnd returned from RegOpenKey()cVal := "AutoEnter"nVal := 1nResult := RegSetValue2( nHnd, cVal, nVal )
Also, I had to change your code slightly as the compiler complained about pW2 being declared within the CASE. Here is revised:
Code: Select all | Expand
#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
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
Merchant Software Corp
Marshall, Virginia USA
-
- Posts: 42
- Joined: Wed Oct 26, 2005 1:20 pm
- Location: Marshall, Virginia, USA
- Contact:
-
- Posts: 42
- Joined: Wed Oct 26, 2005 1:20 pm
- Location: Marshall, Virginia, USA
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42611
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 49 times
- Been thanked: 88 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42611
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 49 times
- Been thanked: 88 times
- Contact:
Bill,
Please try this:
Please try this:
Code: Select all | Expand
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;
-
- Posts: 42
- Joined: Wed Oct 26, 2005 1:20 pm
- Location: Marshall, Virginia, USA
- Contact: