Page 1 of 1

GPF GetDeviceId

Posted: Mon Dec 12, 2005 3:43 pm
by pawelu
Antonio,

I reinstall FwPPc. In previous version function GetDeviceId works fine. In this moment this function produce GPF error. Maybe my code is wrong ?

Regards
Pawel

Code: Select all

#Include 'FwCe.Ch'

Function Serial ()

   MsgInfo (DeviceId ())   

Return .T.

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>
#include <aygshell.h>
#include <uniqueid.h>
#include <objbase.h>

#define MAXSTR 100

BOOL GetDeviceID (GUID* pGuid);

HB_FUNC (DEVICEID)
{
   GUID Guid;
   WCHAR szData[MAXSTR];
   char * szId = "";

   GetDeviceID (&Guid);
   StringFromGUID2 (Guid, szData, MAXSTR);
   wcstombs (szId, (WCHAR *) szData, MAXSTR);
   hb_retc (szId);
   hb_xfree (szId);
}

BOOL GetDeviceID (GUID* pGuid)
{
   BOOL fRes;
   DWORD dwBytesReturned = 0;
   DEVICE_ID* pDevID;
   int wSize;

   if (NULL == pGuid) return FALSE;

   memset (pGuid, 0, sizeof (GUID));

   pDevID = (DEVICE_ID*) malloc (sizeof (DEVICE_ID));
   memset (pDevID, 0, sizeof (DEVICE_ID));
   pDevID->dwSize = sizeof (DEVICE_ID);

   fRes = KernelIoControl (IOCTL_HAL_GET_DEVICEID, NULL, 0, pDevID, sizeof (DEVICE_ID), &dwBytesReturned);

   wSize = pDevID->dwSize;
   free (pDevID);
   if ((FALSE != fRes) || (ERROR_INSUFFICIENT_BUFFER != GetLastError ())) return FALSE;

   pDevID = (DEVICE_ID*) malloc (wSize);
   memset (pDevID, 0, sizeof (wSize));
   pDevID->dwSize = wSize;
   fRes = KernelIoControl (IOCTL_HAL_GET_DEVICEID, NULL, 0, pDevID, wSize, &dwBytesReturned);

   if ((FALSE == fRes) || (ERROR_INSUFFICIENT_BUFFER == GetLastError ())) return FALSE;

   BYTE* pDat = (BYTE*) &pGuid->Data1;
   BYTE* pSrc = (BYTE*) (pDevID) + pDevID->dwPresetIDOffset;
   memcpy (pDat, pSrc, pDevID->dwPresetIDBytes);
   pDat +=  pDevID->dwPresetIDBytes;
   pSrc = (BYTE*) (pDevID) + pDevID->dwPlatformIDOffset;
   memcpy (pDat, pSrc, pDevID->dwPlatformIDBytes);

   return TRUE;
}

#pragma ENDDUMP

Posted: Mon Dec 12, 2005 6:07 pm
by Antonio Linares
Pawel,

Have you reinstalled Harbour too ? It must be reinstalled!

Do you link ole32.lib to build that PRG ?

Posted: Mon Dec 12, 2005 7:45 pm
by pawelu
yes, I reinstall harbour too, in link script I'm always use Ole32.Lib. (After reinstall harbour exe size is larger ca 100kB from old lib)

Pawel

Posted: Mon Dec 12, 2005 7:58 pm
by pawelu
Antonio,

I found, problem solved. I remove line:
hb_xfree (szId)
now this function works fine again in iPaq hx2410 :-)

Thanks,
Pawel

Posted: Mon Dec 12, 2005 9:25 pm
by Antonio Linares
Pawel,

yes, your fix is ok.

Does your code work on the emulator ?

Posted: Mon Dec 12, 2005 10:07 pm
by pawelu
Antonio,

Code works perfect standalone. When I try use it in main program (with several function) this produce indefinitive situation eg. startup dialog is show without use fullscrdlg function etc. Generally, when I use this function it's crash program. In this moment I don't know completly what this happen.
Previous version FwPpc and Harbour works great wih DeviceId function and hb_xfree clause.

DeviceId works fine on emulator.

Pawel

Posted: Tue Dec 13, 2005 9:10 am
by Antonio Linares
Pawel,

My guess is that KernelIoControl (IOCTL_HAL_GET_DEVICEID, ... corrupts the application memory.

Anyhow, could you please send me by email the EXE (as a ZIP) that works ok on the emulator ? Thanks.