GetLastError always returns 538976288

GetLastError always returns 538976288

Post by noeliapera » Wed, 09 Mar 2005 19:13:13


I need retrieve the device name of wireless adapter that I need to
communicate with. The code is below. GestLastError returns
538976288.What happen?
Each call SetupDiEnumDeviceInterfaces returns information about one
device interface, but How I know what's the right device interface of
mi wireless NIC?
GestLastError always returns 538976288.

--------------------------------------------------------------


#include "stdafx.h"

#include <stdio.h>
#include <windows.h>
#include <setupapi.h>
#include <ndisguid.h>
#include <regstr.h>
#include <stdlib.h>
#include <malloc.h>



#using <mscorlib.dll>

#pragma comment( lib, "Setupapi" )



DEFINE_GUID(GUID_NDIS_LAN_CLASS,
0xad498944, 0x762f, 0x11d0, 0x8d, 0xcb, 0x00, 0xc0, 0x4f, 0xc3,
0x35, 0x8c);

using namespace System;
HDEVINFO hDevInfo = INVALID_HANDLE_VALUE;
SP_DEVICE_INTERFACE_DATA didata;
int i;
SP_DEVICE_INTERFACE_DETAIL_DATA diddetail;
PSP_DEVICE_INTERFACE_DETAIL_DATA pdiddetail;
DWORD size=0;
SP_DEVINFO_DATA dinfodata;


int _tmain()
{

hDevInfo=SetupDiGetClassDevs(&GUID_NDIS_LAN_CLASS,
0,
0,
DIGCF_INTERFACEDEVICE);


printf ("\nError: %d \n", GetLastError());

i=0;
didata.cbSize = sizeof(didata);
//Enumero los device interface
int Logica=1;
int logica2;
int logica3;
while (Logica!=0)
{

Logica=SetupDiEnumDeviceInterfaces (hDevInfo,
NULL,
(GUID*)&GUID_NDIS_LAN_CLASS,
i,
&didata);



if (Logica!=0)
{
printf("\nDevice interface numero: %d",i);
printf("\nVariable LOGICA -> %d\n",Logica);


//Obtengo el paretro RequiredSize
logica2=SetupDiGetDeviceInterfaceDetail (hDevInfo,
&didata,
NULL,
0,
&size,
NULL);


if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)
{
printf ("Primer paso OK");
printf ("RequiredSize: %d\n", size);

}
else
{
printf("\Variable Logica2 -> %d\n",logica2);
printf ("Error: %d \n", GetLastError());

}
//Reservo en memoria el tama obtenido de la llamada anterior y
llamo nuevamente a la funci
//SetupDiGetDeviceInterfacesDetail para obtener el
device name

pdiddetail=(PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(size);

diddetail.cbSize = sizeof(diddetail);
logica3=SetupDiGetDeviceInterfaceDetail (hDevInfo,
&didata,
pdiddetail,
size,
NULL,
NULL);

printf("\Variable Logica3 -> %d\n",logica3);

free(pdiddetail);
}
else break;
i++;
didata.cbSize = sizeof(didata);

}

return 0;
}
 
 
 

GetLastError always returns 538976288

Post by Severia » Thu, 10 Mar 2005 00:44:40


<code snipped>

Note 1: 538976288 is 0x20202020, which is four spaces. Could be
corrupted memory because of invalid arguments.

Note 2: The third call to GetLastError (after your call to
SetupDiGetDeviceInterfaceDetail) is preceded by a printf() which may
do any number of system calls that wipe out GetLastError().

Note 3: I'm not familiar with this API, but perhaps, since
SetupDiGetDeviceInterfaceDetail apparently returns a size, maybe it
needs to be called differently. Some Windows APIs will return the size
of the required return area if you pass NULL as the address. Perhaps
you need to do this, then allocate the space and call again.

uena suerte!

Sev