- Code: Select all Expand view
// Serial number
#include "FWCE.ch"
function Main()
local oWnd
DEFINE WINDOW oWnd TITLE "Serial Nº"
@ 2, 2 BUTTON "Serial Nº" SIZE 80, 25 ACTION MsgInfo( SerialNumber() )
ACTIVATE WINDOW oWnd
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <uniqueid.h>
HB_FUNC( SERIALNUMBER )
{
DWORD dwOutBytes;
const int nBuffSize = 4096;
byte arrOutBuff[ nBuffSize ];
BOOL bResult = KernelIoControl( IOCTL_HAL_GET_DEVICEID, 0, 0,
arrOutBuff, nBuffSize, &dwOutBytes);
char strDeviceId[ 18 ];
char hex[ 17 ] = "0123456789ABCDEF";
if( bResult == FALSE )
{
hb_retc( "0" );
}
else
{
strDeviceId[ 0 ] = hex[ arrOutBuff[ 40 ] ];
strDeviceId[ 1 ] = hex[ arrOutBuff[ 41 ] ];
strDeviceId[ 2 ] = hex[ arrOutBuff[ 45 ] ];
strDeviceId[ 3 ] = hex[ arrOutBuff[ 46 ] ];
strDeviceId[ 4 ] = hex[ arrOutBuff[ 47 ] ];
strDeviceId[ 5 ] = hex[ arrOutBuff[ 48 ] ];
strDeviceId[ 6 ] = hex[ arrOutBuff[ 49 ] ];
strDeviceId[ 7 ] = hex[ arrOutBuff[ 50 ] ];
strDeviceId[ 8 ] = hex[ arrOutBuff[ 51 ] ];
strDeviceId[ 9 ] = hex[ arrOutBuff[ 52 ] ];
strDeviceId[ 10 ] = hex[ arrOutBuff[ 53 ] ];
strDeviceId[ 11 ] = hex[ arrOutBuff[ 70 ] ];
strDeviceId[ 12 ] = hex[ arrOutBuff[ 71 ] ];
strDeviceId[ 13 ] = hex[ arrOutBuff[ 72 ] ];
strDeviceId[ 14 ] = hex[ arrOutBuff[ 73 ] ];
strDeviceId[ 15 ] = hex[ arrOutBuff[ 74 ] ];
strDeviceId[ 16 ] = hex[ arrOutBuff[ 75 ] ];
strDeviceId[ 17 ] = 0;
hb_retc( strDeviceId );
}
}
#pragma ENDDUMP
Original source code:
- Code: Select all Expand view
#include <uniqueid.h>
CString GetDeviceSerialNumber()
{
DWORD dwOutBytes;
const int nBuffSize = 4096;
byte arrOutBuff[nBuffSize];
BOOL bResult = ::KernelIoControl(IOCTL_HAL_GET_DEVICEID,
0, 0, arrOutBuff, nBuffSize, &dwOutBytes);
if (bResult == FALSE)
{
return _T("");
}
CString strDeviceInfo;
for (unsigned int i = 0; i<dwOutBytes; i++)
{
CString strNextChar;
strNextChar.Format(L"%02X", arrOutBuff[i]);
strDeviceInfo += strNextChar;
}
CString strDeviceId =
strDeviceInfo.Mid(40,2) +
strDeviceInfo.Mid(45,9) +
strDeviceInfo.Mid(70,6);
return strDeviceId;
}