指定客户端信息
某些设备驱动程序使用第二个参数中提供的客户端信息来优化设备性能。 应用程序至少应提供一个包含其名称、主版本号、次要版本号和修订号的字符串。 这些是示例应用程序提供的字段。
#define CLIENT_NAME L"WPD Sample Application"
#define CLIENT_MAJOR_VER 1
#define CLIENT_MINOR_VER 0
#define CLIENT_REVISION 2
GetClientInformation
示例应用程序中的 函数使用客户端信息创建并填充 IPortableDeviceValues 接口。 此函数有两个主要部分。 第一部分通过调用 CoCreateInstance 函数创建可移植设备值对象的实例。
HRESULT hr = CoCreateInstance(CLSID_PortableDeviceValues,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(ppClientInformation));
第二部分设置可移植设备值对象中的客户端信息。
if (SUCCEEDED(hr))
{
// Attempt to set all bits of client information
hr = (*ppClientInformation)->SetStringValue(WPD_CLIENT_NAME, CLIENT_NAME);
if (FAILED(hr))
{
printf("! Failed to set WPD_CLIENT_NAME, hr = 0x%lx\n",hr);
}
hr = (*ppClientInformation)->SetUnsignedIntegerValue(WPD_CLIENT_MAJOR_VERSION, CLIENT_MAJOR_VER);
if (FAILED(hr))
{
printf("! Failed to set WPD_CLIENT_MAJOR_VERSION, hr = 0x%lx\n",hr);
}
hr = (*ppClientInformation)->SetUnsignedIntegerValue(WPD_CLIENT_MINOR_VERSION, CLIENT_MINOR_VER);
if (FAILED(hr))
{
printf("! Failed to set WPD_CLIENT_MINOR_VERSION, hr = 0x%lx\n",hr);
}
hr = (*ppClientInformation)->SetUnsignedIntegerValue(WPD_CLIENT_REVISION, CLIENT_REVISION);
if (FAILED(hr))
{
printf("! Failed to set WPD_CLIENT_REVISION, hr = 0x%lx\n",hr);
}
// Some device drivers need to impersonate the caller in order to function correctly. Since our application does not
// need to restrict its identity, specify SECURITY_IMPERSONATION so that we work with all devices.
hr = (*ppClientInformation)->SetUnsignedIntegerValue(WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, SECURITY_IMPERSONATION);
if (FAILED(hr))
{
printf("! Failed to set WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, hr = 0x%lx\n",hr);
}
}
else
{
printf("! Failed to CoCreateInstance CLSID_PortableDeviceValues, hr = 0x%lx\n",hr);
}
相关主题