|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 200876 - Last Review: August 17, 2004 - Revision: 2.0 How To Get Information for a Specific Display Device DriverThis article was previously published under Q200876
This article describes a technique that allows an application to obtain information about a specified display device on a Windows 95 or Windows 98 system.
On Windows 98 systems, multiple display devices can coexist on a system. There is no API available that allows you to obtain information about the display devices directly from the system. This articles describes a technique for parsing the registry database to obtain this information.
The sample code uses the FindDevice() function to search for devices with a specified Class name. After the device is found, the GetDeviceValue() function is used to get the details for the device.
//
// Function : GetDeviceValue
//
// Purpose : Read a value from the HW or SW of a PnP device.
//
// Parameters :
// szHardwareKey Hardware key for the device.
// szKey Subkey.
// szValue The value to be queried.
// buf Buffer to receive the value.
// cbbuf Size of buffer.
//
// Returns : TRUE if value is obtained.
//
BOOL GetDeviceValue(LPCSTR szHardwareKey, LPSTR szKey, LPSTR Value,
BYTE *buf, DWORD cbbuf)
{
HKEY hkeyHW;
HKEY hkeySW;
BOOL bFlag = FALSE;
DWORD nSize;
char szSoftwareKey[MAX_PATH];
*(DWORD*)buf = 0;
//
// Open the HW key.
//
if (RegOpenKey(HKEY_LOCAL_MACHINE, szHardwareKey, &hkeyHW) ==
ERROR_SUCCESS)
{
//
// Try to read the value from the HW key.
//
*buf = 0;
nSize = cbbuf;
if (RegQueryValueEx(hkeyHW, szValue, NULL, NULL, buf,
&nSize) == ERROR_SUCCESS)
{
bFlag = TRUE;
}
else
{
//
// Now try the SW key.
//
static char szSW[] =
"System\\CurrentControlSet\\Services\\Class\\";
lstrcpy(szSoftwareKey, szSW);
nSize = sizeof(szSoftwareKey) - sizeof(szSW);
RegQueryValueEx(hkeyHW, "Driver", NULL, NULL, szSoftwareKey
+ sizeof(szSW) - 1, &nSize);
if (szKey)
{
lstrcat(szSoftwareKey, "\\");
lstrcat(szSoftwareKey, szKey);
}
if (RegOpenKey(HKEY_LOCAL_MACHINE, szSoftwareKey,
&hkeySW) == ERROR_SUCCESS)
{
*buf = 0;
nSize = cbbuf;
if (RegQueryValueEx(hkeySW, szValue, NULL, NULL, buf,
&nSize) == ERROR_SUCCESS)
{
bFlag = TRUE;
}
RegCloseKey(hkeySW);
}
}
RegCloseKey(hkeyHW);
}
return bFlag;
}
//
// Function : FindDevice
//
// Purpose : Enumerates the started PnP devices looking for a
// device of a particular class.
//
// Parameters :
// iDeviceNumber What device to return (0=first device, 1=second, etc.)
// szDeviceClass What class device (for example, "Display"). NULL will
// match all.
// szDeviceID Buffer to return the hardware ID (MAX_PATH bytes).
//
// Return : TRUE if a device was found.
//
// Example:
//
// for (int i=0; FindDevice(i, "Display", DeviceID); i++)
// {
// }
//
BOOL FindDevice(int iDeviceNumber, LPCSTR szDeviceClass, LPSTR
szHardwareKey)
{
HKEY hkeyPnP;
HKEY hkey;
DWORD nCounter;
DWORD nSize;
DWORD dwReturnValue;
char szBuffer[MAX_PATH];
if (RegOpenKey(HKEY_DYN_DATA, "Config Manager\\Enum", &hkeyPnP)
!= ERROR_SUCCESS)
return FALSE;
for (nCounter=0; RegEnumKey(hkeyPnP, nCounter, szBuffer,
sizeof(szBuffer)) == 0; nCounter++)
{
static char szHW[] = "Enum\\";
if (RegOpenKey(hkeyPnP, szBuffer, &hkey) != ERROR_SUCCESS)
continue;
lstrcpy(szHardwareKey, szHW);
nSize = MAX_PATH - sizeof(szHW);
RegQueryValueEx(hkey, "HardwareKey", NULL, NULL,
(BYTE*)szHardwareKey + sizeof(szHW) - 1, &nSize);
dwReturnValue = 0;
nSize = sizeof(dwReturnValue);
RegQueryValueEx(hkey, "Problem", NULL, NULL,
(BYTE*)&dwReturnValue, &nSize);
RegCloseKey(hkey);
if (dwReturnValue != 0) // If this device has a problem,
// skip it.
continue;
if (szDeviceClass)
{
GetDeviceValue(szHardwareKey, NULL, "Class", szBuffer,
sizeof(szBuffer));
if (lstrcmpi(szDeviceClass, szBuffer) != 0)
continue;
}
//
// You found a device; make sure it is the one the caller wants.
//
if (iDeviceNumber-- == 0)
{
RegCloseKey(hkeyPnP);
return TRUE;
}
}
RegCloseKey(hkeyPnP);
return FALSE;
}
void main(int argc, char **argv)
{
int iDeviceCounter;
char szKey[MAX_PATH];
char szValue[MAX_PATH];
#define GETSZ(a, b) \
GetDeviceValue(szKey, a, b, szValue, sizeof(szValue)); \
printf(" %-20s:\t%s\n", b, szValue);
for (iDeviceCounter=0; FindDevice(iDeviceCounter, "Display", szKey);
iDeviceCounter++)
{
printf("**** Display %d\n", iDeviceCounter+1);
GETSZ(NULL, "DeviceDesc");
GETSZ(NULL, "DriverDesc");
GETSZ(NULL, "DriverDate");
GETSZ(NULL, "ProviderName");
GETSZ(NULL, "Mfg");
GETSZ("DEFAULT", "drv");
GETSZ("DEFAULT", "minivdd");
}
}
APPLIES TO- Microsoft Win32 Device Driver Kit for Windows 2000
- Microsoft Win32 Device Driver Kit for Windows 2000
| kbdisplay kbfaq kbhowto kbvideotech KB200876 |
Retired KB Content DisclaimerThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
 |
 |
 |
 |
 |
 |
 |
| |