GPF GetDeviceId

Post Reply
pawelu
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland
Contact:

GPF GetDeviceId

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Pawel,

Have you reinstalled Harbour too ? It must be reinstalled!

Do you link ole32.lib to build that PRG ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
pawelu
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland
Contact:

Post 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
pawelu
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland
Contact:

Post by pawelu »

Antonio,

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

Thanks,
Pawel
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Pawel,

yes, your fix is ok.

Does your code work on the emulator ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
pawelu
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland
Contact:

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply