Hardware list error
-
It is the code from MSDN It complies and links but does not executes giving the following error File:i386\chkesp.c line:48 The value of ESP was not properly saved across a fuction call.This is usually a result of calling function decleared with one calling convention with a funciton pointer decleared with a different calling convention. #include #include #include DWORD Err; HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid) /* Routine Description: Retrieves the device information set that contains that contains the devices of the specified class. Parameters: InterfaceClassGuid - The interface class GUID. Return Value: If the function succeeds, the return value is a handle to the device information set. If the function fails, the return value is zero. */ { HDEVINFO DeviceInfoSet; HDEVINFO NewDeviceInfoSet; // Create a device information set that will be the container for // the device interfaces. DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL); if(DeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err ); return 0; } // Retrieve the device information set for the interface class. NewDeviceInfoSet = SetupDiGetClassDevsEx( &InterfaceClassGuid, // address of guid required NULL, // no enumerator NULL, // no parent window handle (might not be a good idea…) DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, // flags //DeviceInfoSet, // do not pass this in, not in function prototype NULL, // NULL implies local machine NULL // Reserved’ must be null ); if(NewDeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err ); return 0; } return NewDeviceInfoSet; } int main(int argc, TCHAR* argv[]) { GUID var; DoDeviceEnum(var); return 0; }
-
It is the code from MSDN It complies and links but does not executes giving the following error File:i386\chkesp.c line:48 The value of ESP was not properly saved across a fuction call.This is usually a result of calling function decleared with one calling convention with a funciton pointer decleared with a different calling convention. #include #include #include DWORD Err; HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid) /* Routine Description: Retrieves the device information set that contains that contains the devices of the specified class. Parameters: InterfaceClassGuid - The interface class GUID. Return Value: If the function succeeds, the return value is a handle to the device information set. If the function fails, the return value is zero. */ { HDEVINFO DeviceInfoSet; HDEVINFO NewDeviceInfoSet; // Create a device information set that will be the container for // the device interfaces. DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL); if(DeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err ); return 0; } // Retrieve the device information set for the interface class. NewDeviceInfoSet = SetupDiGetClassDevsEx( &InterfaceClassGuid, // address of guid required NULL, // no enumerator NULL, // no parent window handle (might not be a good idea…) DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, // flags //DeviceInfoSet, // do not pass this in, not in function prototype NULL, // NULL implies local machine NULL // Reserved’ must be null ); if(NewDeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err ); return 0; } return NewDeviceInfoSet; } int main(int argc, TCHAR* argv[]) { GUID var; DoDeviceEnum(var); return 0; }
Put a breakpoint on the
SetupDiCreateDeviceInfoList()
statement and single-step through the code until you get to the statement that causes the error. I cleaned up your code a bit to look like:HDEVINFO DoDeviceEnum( void )
{
GUID InterfaceClassGuid;
HDEVINFO DeviceInfoSet,
NewDeviceInfoSet;DeviceInfoSet = SetupDiCreateDeviceInfoList(&InterfaceClassGuid, NULL); if (DeviceInfoSet != INVALID\_HANDLE\_VALUE) { NewDeviceInfoSet = SetupDiGetClassDevsEx(&InterfaceClassGuid, NULL, NULL, DIGCF\_PRESENT | DIGCF\_DEVICEINTERFACE, DeviceInfoSet, NULL, NULL); if (NewDeviceInfoSet != INVALID\_HANDLE\_VALUE) ; // do something with the list else printf("SetupDiGetClassDevsEx failed: %lu.\\n", GetLastError()); SetupDiDestroyDeviceInfoList(DeviceInfoSet); } else printf("SetupDiCreateDeviceInfoList failed: %lu.\\n", GetLastError()); return NewDeviceInfoSet;
}
void main( void )
{
DoDeviceEnum();
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow