Error in function nSerialHD ()

Error in function nSerialHD ()

Postby StefanHaupt » Tue Nov 04, 2008 9:01 am

Antonio,

maybe I found an error in the function nSerialHD(). It always returns negative values.

If I change hb_retnl (..) to hb_retnll (..) it is working correct.

Code: Select all  Expand view
HB_FUNC( NSERIALHD )
{
   DWORD dwVolumeSerialNumber;
   BYTE VolumeNameBuffer[ 256 ];
   BYTE FileSystemNameBuffer[ 256 ];

   GetVolumeInformation( hb_pcount() ? hb_parc( 1 ): "C:\\",
                         ( char * ) VolumeNameBuffer, sizeof( VolumeNameBuffer ),
                         &dwVolumeSerialNumber, 0, 0,
                         ( char * ) FileSystemNameBuffer,
                         sizeof( FileSystemNameBuffer ) );

   hb_retnll( dwVolumeSerialNumber );   //<------
}


Can you check this, please
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Error in function nSerialHD ()

Postby Patrick Mast » Tue Nov 04, 2008 9:27 am

StefanHaupt wrote:Antonio,

maybe I found an error in the function nSerialHD(). It always returns negative values.

If I change hb_retnl (..) to hb_retnll (..) it is working correct.

Code: Select all  Expand view
HB_FUNC( NSERIALHD )
{
   DWORD dwVolumeSerialNumber;
   BYTE VolumeNameBuffer[ 256 ];
   BYTE FileSystemNameBuffer[ 256 ];

   GetVolumeInformation( hb_pcount() ? hb_parc( 1 ): "C:\",
                         ( char * ) VolumeNameBuffer, sizeof( VolumeNameBuffer ),
                         &dwVolumeSerialNumber, 0, 0,
                         ( char * ) FileSystemNameBuffer,
                         sizeof( FileSystemNameBuffer ) );

   hb_retnll( dwVolumeSerialNumber );   //<------
}


Can you check this, please

Lets be carefull with this function. In my app for example, I use this function to activate my app on THIS HD. If this function suddenly returns a different number, my apps will all DE-activate.

Thanks.

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Tue Nov 04, 2008 9:41 am

Stefan,

A negative value means a numeric value with the "sign bit" on (left most bit).

If you want it as a positive number, you just need to calculate the complementary number.

In other words: there are no "negative" numbers. The "sign bit" may be on or off, and then we can interpret it as we may need it.

I am not sure if I am quite clear about it :-)
regards, saludos

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

Postby Antonio Linares » Tue Nov 04, 2008 9:42 am

regards, saludos

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

Postby Antonio Linares » Tue Nov 04, 2008 9:55 am

Stefan,

Your solution as a function:
Code: Select all  Expand view
function Main()

   MsgInfo( NoSign( HexToDec( "FFFFFFFF" ) ) )
   
return nil

#pragma BEGINDUMP

#include <hbapi.h>

HB_FUNC( NOSIGN )
{
   hb_retnll( ( unsigned long ) hb_parnl( 1 ) );
}

#pragma ENDDUMP
regards, saludos

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

Re: Error in function nSerialHD ()

Postby StefanHaupt » Tue Nov 04, 2008 12:26 pm

Patrick Mast wrote:Lets be carefull with this function. In my app for example, I use this function to activate my app on THIS HD. If this function suddenly returns a different number, my apps will all DE-activate.


Patrick,

I see the problem, you (and maybe others) will get, changing this function. I discovered this issue comparing the return values of nSerialHD (FWH) and VolSerial (xHarbour). VolSerial() returns imho the right value.

It´s very confusing if two functions that do the same are returning different values.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby StefanHaupt » Tue Nov 04, 2008 12:39 pm

Antonio,

thanks for your explanation, you are right, in computer numbering there are no negative values.

Your solution overcomes any problem concerning existing applications using this function for protection.

But nevertheless it is very confusing if two functions with the same functionality return different values (comparing nSerialHD() and HexToDec() with VolSerial() and HexToNum() from xHarbour)
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Antonio Linares » Tue Nov 04, 2008 1:23 pm

Stefan,

The problem comes from the fact that in 32 bits hb_retnl() is unable to return an unsigned number (from a certain values range).

Using the function NoSign() we can easily solve it and we can keep backwards compatibility :-)
regards, saludos

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

Postby StefanHaupt » Wed Nov 05, 2008 8:42 am

Antonio Linares wrote:Using the function NoSign() we can easily solve it and we can keep backwards compatibility :-)


Yes, I agree
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Patrick Mast » Wed Nov 05, 2008 8:46 am

Antonio Linares wrote:Using the function NoSign() we can easily solve it and we can keep backwards compatibility :-)

But this still changes the return value correct? So, my save HD serial nr will not be valid anymore?

Patrick
User avatar
Patrick Mast
 
Posts: 246
Joined: Sat Mar 03, 2007 8:42 pm

Postby Antonio Linares » Wed Nov 05, 2008 10:01 am

Patrick,

We are not modifying nSerialHD() at all :-)

So we keep full backwards compatibility. function NoSign() is there for those that want such value without sign.
regards, saludos

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 43 guests