我是在看pm电源管理的mdd层代码的时候发现的,pmimpl.h,pmstream.cpp
// this structure describes a power-manageable device
typedef struct _DeviceState_tag {
LPCTSTR pszName; // device's name
CEDEVICE_POWER_STATE curDx; // current official power state (not necessarily supported by the device)
CEDEVICE_POWER_STATE floorDx; // minimum device power state, or PwrDeviceUnspecified
CEDEVICE_POWER_STATE ceilingDx; // maximum device power state, or PwrDeviceUnspecified
CEDEVICE_POWER_STATE setDx; // power state if explicitly set, or PwrDeviceUnspecified
CEDEVICE_POWER_STATE lastReqDx; // last state requested by the device
CEDEVICE_POWER_STATE actualDx; // current actual device power state
CEDEVICE_POWER_STATE pendingDx; // Pending DX for updating
DWORD dwNumPending; // Number of Pending for updating.
struct _DeviceState_tag *pParent; // parent device, or NULL POWER_CAPABILITIES caps; // as reported by the device
DWORD dwRefCount; // structure can be deallocated when this is 0
HANDLE hDevice; // handle to the device from OpenDevice(), or NULL
PDEVICE_INTERFACE pInterface; // interface to the device class power management routines
struct _DeviceList_tag *pListHead; // pointer to the containing list
struct _DeviceState_tag *pNext; // linked list pointers
struct _DeviceState_tag *pPrev;
} DEVICE_STATE, *PDEVICE_STATE;
static HANDLE
OpenStreamDevice(PDEVICE_STATE pds)
{
PDEVICE_STATE pdsReal = pds;
SETFNAME(_T("OpenStreamDevice"));
// determine what device to actually open
if(pds->pParent != NULL) {
pdsReal = pds->pParent;
}
// get a handle to the client
HANDLE hRet = CreateFile(pdsReal->pszName, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hRet == INVALID_HANDLE_VALUE) {
PMLOGMSG(ZONE_WARN || ZONE_IOCTL, (_T("%s: OpenFile('%s') failed %d (0x%08x)\r\n"), pszFname,
pdsReal->pszName, GetLastError(), GetLastError()));
}
PMLOGMSG(ZONE_DEVICE || ZONE_IOCTL, (_T("%s: handle to '%s' on behalf of '%s' is 0x%08x\r\n"), \
pszFname, pdsReal->pszName, pds->pszName, hRet));
return hRet;
}
打开一个流接口设备的时候,获取的是他的父设备的句柄,我开始我有点奇怪,后来发现,在添加设备的时候,那个parent的参数是NULL的,也就是wince6.0中还没有用到,留着以后用。具体这也都是我的猜测。
详情回复
发表于 2010-4-1 17:17
我是在看pm电源管理的mdd层代码的时候发现的,pmimpl.h,pmstream.cpp
// this structure describes a power-manageable device
typedef struct _DeviceState_tag {
LPCTSTR pszName; // device's name
CEDEVICE_POWER_STATE curDx; // current official power state (not necessarily supported by the device)
CEDEVICE_POWER_STATE floorDx; // minimum device power state, or PwrDeviceUnspecified
CEDEVICE_POWER_STATE ceilingDx; // maximum device power state, or PwrDeviceUnspecified
CEDEVICE_POWER_STATE setDx; // power state if explicitly set, or PwrDeviceUnspecified
CEDEVICE_POWER_STATE lastReqDx; // last state requested by the device
CEDEVICE_POWER_STATE actualDx; // current actual device power state
CEDEVICE_POWER_STATE pendingDx; // Pending DX for updating
DWORD dwNumPending; // Number of Pending for updating.
struct _DeviceState_tag *pParent; // parent device, or NULL POWER_CAPABILITIES caps; // as reported by the device
DWORD dwRefCount; // structure can be deallocated when this is 0
HANDLE hDevice; // handle to the device from OpenDevice(), or NULL
PDEVICE_INTERFACE pInterface; // interface to the device class power management routines
struct _DeviceList_tag *pListHead; // pointer to the containing list
struct _DeviceState_tag *pNext; // linked list pointers
struct _DeviceState_tag *pPrev;
} DEVICE_STATE, *PDEVICE_STATE;
static HANDLE
OpenStreamDevice(PDEVICE_STATE pds)
{
PDEVICE_STATE pdsReal = pds;
SETFNAME(_T("OpenStreamDevice"));
// determine what device to actually open
if(pds->pParent != NULL) {
pdsReal = pds->pParent;
}
// get a handle to the client
HANDLE hRet = CreateFile(pdsReal->pszName, 0,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hRet == INVALID_HANDLE_VALUE) {
PMLOGMSG(ZONE_WARN || ZONE_IOCTL, (_T("%s: OpenFile('%s') failed %d (0x%08x)\r\n"), pszFname,
pdsReal->pszName, GetLastError(), GetLastError()));
}
PMLOGMSG(ZONE_DEVICE || ZONE_IOCTL, (_T("%s: handle to '%s' on behalf of '%s' is 0x%08x\r\n"), \
pszFname, pdsReal->pszName, pds->pszName, hRet));