RegSetValue()

Post Reply
Bill Simmeth
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA
Contact:

RegSetValue()

Post by Bill Simmeth »

It seems the function only stores STRING values? How can I store DWORD and BINARY values to the PPC registry?

Thanks.
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
User avatar
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:

Post by Antonio Linares »

Bill,

We are going to modify RegSetValue(), thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
Bill Simmeth
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA
Contact:

Post by Bill Simmeth »

Very good, thanks!
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
User avatar
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:

Post by Antonio Linares »

Bill,

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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Bill Simmeth
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA
Contact:

Post by Bill Simmeth »

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:

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
Bill Simmeth
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA
Contact:

Post by Bill Simmeth »

Antonio,

I would be in favor of adding an optional fourth parameter to allow for BINARY values. I have an important need for this.

Thanks,
Bill
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
Bill Simmeth
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA
Contact:

Post by Bill Simmeth »

Sorry, I forgot to add that using the function to set a REG_SZ (text) value works fine.
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
User avatar
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:

Post by Antonio Linares »

Bill,

We are going to review it asap
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
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:

Post by Antonio Linares »

Bill,

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; 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Bill Simmeth
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA
Contact:

Post by Bill Simmeth »

Antonio, thanks. That change works. So, now REG_SZ and DWORD values are working.
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
Post Reply