GPF GetDeviceId

GPF GetDeviceId

Postby pawelu » Mon Dec 12, 2005 3:43 pm

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  Expand view  RUN
#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
pawelu
 
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland

Postby Antonio Linares » Mon Dec 12, 2005 6:07 pm

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

Postby pawelu » Mon Dec 12, 2005 7:45 pm

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

Postby pawelu » Mon Dec 12, 2005 7:58 pm

Antonio,

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

Thanks,
Pawel
pawelu
 
Posts: 126
Joined: Thu Oct 06, 2005 10:18 pm
Location: Poland

Postby Antonio Linares » Mon Dec 12, 2005 9:25 pm

Pawel,

yes, your fix is ok.

Does your code work on the emulator ?
regards, saludos

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

Postby pawelu » Mon Dec 12, 2005 10:07 pm

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

Postby Antonio Linares » Tue Dec 13, 2005 9:10 am

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


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 43 guests