RegSetValue()

RegSetValue()

Postby Bill Simmeth » 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.
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
Bill Simmeth
 
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA

Postby Antonio Linares » Mon Jan 08, 2007 5:45 pm

Bill,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Bill Simmeth » Mon Jan 08, 2007 5:57 pm

Very good, thanks!
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
Bill Simmeth
 
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA

Postby Antonio Linares » Tue Jan 09, 2007 7:58 am

Bill,

This one should work for strings and numbers (not decimals):
Code: Select all  Expand view  RUN
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Bill Simmeth » Tue Jan 09, 2007 3:34 pm

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 view  RUN
//nHnd returned from RegOpenKey()
cVal := "AutoEnter"
nVal := 1

nResult := 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 view  RUN
#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

Postby Bill Simmeth » Tue Jan 09, 2007 3:43 pm

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

Postby Bill Simmeth » Tue Jan 09, 2007 4:01 pm

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

Postby Antonio Linares » Tue Jan 09, 2007 10:42 pm

Bill,

We are going to review it asap
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Tue Jan 09, 2007 10:45 pm

Bill,

Please try this:
Code: Select all  Expand view  RUN
         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
User avatar
Antonio Linares
Site Admin
 
Posts: 42103
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Bill Simmeth » Wed Jan 10, 2007 1:10 pm

Antonio, thanks. That change works. So, now REG_SZ and DWORD values are working.
Bill Simmeth
Merchant Software Corp
Marshall, Virginia USA
Bill Simmeth
 
Posts: 42
Joined: Wed Oct 26, 2005 1:20 pm
Location: Marshall, Virginia, USA


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 5 guests