Page 1 of 1

Error in function nSerialHD ()

Posted: Tue Nov 04, 2008 9:01 am
by StefanHaupt
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

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

Re: Error in function nSerialHD ()

Posted: Tue Nov 04, 2008 9:27 am
by Patrick Mast
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

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

Posted: Tue Nov 04, 2008 9:41 am
by Antonio Linares
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 :-)

Posted: Tue Nov 04, 2008 9:42 am
by Antonio Linares

Posted: Tue Nov 04, 2008 9:55 am
by Antonio Linares
Stefan,

Your solution as a function:

Code: Select all

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 

Re: Error in function nSerialHD ()

Posted: Tue Nov 04, 2008 12:26 pm
by StefanHaupt
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.

Posted: Tue Nov 04, 2008 12:39 pm
by StefanHaupt
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)

Posted: Tue Nov 04, 2008 1:23 pm
by Antonio Linares
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 :-)

Posted: Wed Nov 05, 2008 8:42 am
by StefanHaupt
Antonio Linares wrote:Using the function NoSign() we can easily solve it and we can keep backwards compatibility :-)
Yes, I agree

Posted: Wed Nov 05, 2008 8:46 am
by Patrick Mast
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

Posted: Wed Nov 05, 2008 10:01 am
by Antonio Linares
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.