📄 testwmi.cpp
字号:
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright 2000 Microsoft Corporation. All Rights Reserved.
//
// PROGRAM: testwmi.cpp
//
// AUTHOR: Alok Sinha August 15, 2000
//
// PURPOSE: To test getting/setting custom classs of E100BEX driver.
//
// ENVIRONMENT: Windows 2000 user mode application.
//
#include "testwmi.h"
//
// List of custom classes as defined in E100BEX sample.
//
// If you want to use this application to excersize querying/setting guids
// exported by your driver then, simply add the class name of the guid
// to the following array and recompile the program.
//
LPTSTR lpszClasses[] = {
TEXT("E100BExampleSetUINT_OID"),
TEXT("E100BExampleQueryUINT_OID"),
TEXT("E100BExampleQueryArrayOID"),
TEXT("E100BExampleQueryStringOID")
};
//
// Handle to this instance of the application.
//
HINSTANCE hInstance;
//
// Program entry point.
//
int APIENTRY WinMain (HINSTANCE hInst,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HRESULT hr;
hInstance = hInst;
//
// Make sure common control DLL is loaded.
//
InitCommonControls();
//
// Initialize COM library. Must be done before invoking any
// other COM function.
//
hr = CoInitializeEx( NULL,
COINIT_MULTITHREADED );
if ( hr != S_OK ) {
PrintError( hr,
__LINE__,
TEXT(__FILE__),
TEXT("Failed to initialize COM library, program exiting...") );
}
else {
hr = CoInitializeSecurity( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IDENTIFY,
NULL,
EOAC_NONE,
0 );
if ( hr == S_OK ) {
if ( DialogBox(hInstance,
MAKEINTRESOURCE(IDD_MAIN),
NULL,
MainDlgProc) == -1 ) {
PrintError( HRESULT_FROM_WIN32(GetLastError()),
__LINE__,
TEXT(__FILE__),
TEXT("Failed to create the dialog box, ")
TEXT("program exiting...") );
}
}
else {
PrintError( hr,
__LINE__,
TEXT(__FILE__),
TEXT("CoInitializeSecurity failed, program exiting...") );
}
CoUninitialize();
}
return 0;
}
//
// Windows procedure for the main dialog box.
//
INT_PTR CALLBACK MainDlgProc (HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
IWbemServices *pIWbemServices;
LPNMTREEVIEW lpnmTreeView;
switch (uMsg) {
case WM_INITDIALOG:
//
// Connect to the default namespace.
//
pIWbemServices = ConnectToNamespace();
if ( !pIWbemServices ) {
EndDialog( hwndDlg, 0 );
}
//
// At DWLP_USER offset, we store pIWbemServices so we can
// get to it later.
//
SetWindowLongPtr(
hwndDlg,
DWLP_USER,
(LONG_PTR)pIWbemServices );
//
// Enumerate default classes and its instances. Also,
// show properties of the first instance.
//
ListDefaults( hwndDlg );
return TRUE; // Tell Windows to continue creating the dialog box.
case WM_COMMAND:
switch( LOWORD(wParam) ) {
case IDL_CLASSES:
if ( HIWORD(wParam) == LBN_SELCHANGE ) {
//
// User selected a class. Show its instances and
// the properties of the first instance.
//
RefreshOnClassSelection( hwndDlg );
}
break;
}
break;
case WM_NOTIFY:
switch( wParam ) {
case IDT_INSTANCES:
lpnmTreeView = (LPNMTREEVIEW)lParam;
if ( (lpnmTreeView->hdr.code == TVN_SELCHANGED) &&
(lpnmTreeView->action != TVC_UNKNOWN) ) {
//
// User has clicked on an instance, list its properties.
//
ShowProperties( hwndDlg,
lpnmTreeView->hdr.hwndFrom );
}
break;
case IDT_PROPERTIES:
lpnmTreeView = (LPNMTREEVIEW)lParam;
if ( lpnmTreeView->hdr.code == NM_DBLCLK ) {
//
// User has double-clicked on a property.
//
EditProperty( hwndDlg,
lpnmTreeView->hdr.hwndFrom );
}
break;
}
break;
case WM_SYSCOMMAND:
//
// Before exiting...
// .Make sure to disconnect from the namespace.
//
if ( (0xFFF0 & wParam) == SC_CLOSE ) {
pIWbemServices = (IWbemServices *)GetWindowLongPtr(
hwndDlg,
DWLP_USER );
pIWbemServices->Release();
EndDialog( hwndDlg, 0 );
}
}
return FALSE;
}
//
// Windows procedure to view/modify scalar properties.
//
INT_PTR CALLBACK DlgProcScalar (HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
LPPROPERTY_INFO pPropInfo;
VARIANT vaTemp;
LPTSTR lpszValue;
HRESULT hr;
switch (uMsg) {
case WM_INITDIALOG:
//
// lParam points to PROPERTY_INFO structure which contains information
// the property whose valuse is to be viewed/modified. We store this
// pointer at DWLP_USER offset, so we get to it later.
//
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)lParam );
pPropInfo = (LPPROPERTY_INFO)lParam;
//
// Property name is the title of the dialog box.
//
SetWindowText( hwndDlg,
pPropInfo->lpszProperty );
//
// Show the property type.
//
if ( pPropInfo->lpszType ) {
SetWindowText( GetDlgItem(hwndDlg,
IDS_PROPERTY_TYPE),
pPropInfo->lpszType );
}
//
// Change the property value to a string so it can be displayed
// if the property has a value.
//
if ( (V_VT(pPropInfo->pvaValue) != VT_NULL) &&
(V_VT(pPropInfo->pvaValue) != VT_EMPTY) ) {
VariantInit( &vaTemp );
hr = VariantChangeType( &vaTemp,
pPropInfo->pvaValue,
VARIANT_LOCALBOOL,
VT_BSTR );
if ( hr != S_OK ) {
PrintError( hr,
__LINE__,
TEXT(__FILE__),
TEXT("Couldn't format the value of %s into ")
TEXT("displayable text. The value cannot be ")
TEXT(" viewed/modified."),
pPropInfo->lpszProperty );
EndDialog( hwndDlg, 0 );
}
lpszValue = BstrToString( V_BSTR(&vaTemp),
-1 );
if ( lpszValue ) {
SetWindowText( GetDlgItem(hwndDlg,
IDE_PROPERTY_VALUE),
lpszValue );
SysFreeString( (BSTR)((PVOID)lpszValue));
}
else {
PrintError( HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY),
__LINE__,
TEXT(__FILE__),
TEXT("Cannot show the value of %s."),
pPropInfo->lpszProperty );
EndDialog( hwndDlg, 0 );
}
VariantClear( &vaTemp );
}
return TRUE; // Tell Windows to continue creating the dialog box.
case WM_COMMAND:
switch( LOWORD(wParam) ) {
case IDB_MODIFY:
if ( HIWORD(wParam) == BN_CLICKED ) {
//
// User wants to update the instance after modifying the
// property value.
//
if ( ModifyProperty(hwndDlg) ) {
EndDialog( hwndDlg, 0 );
}
}
break;
case IDB_CANCEL:
if ( HIWORD(wParam) == BN_CLICKED ) {
EndDialog( hwndDlg, 0 );
}
break;
}
break;
case WM_SYSCOMMAND:
if ( (0xFFF0 & wParam) == SC_CLOSE ) {
EndDialog( hwndDlg, 0 );
}
}
return FALSE;
}
//
// Windows procedure to view/modify array properties.
//
INT_PTR CALLBACK DlgProcArray (HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
LPPROPERTY_INFO pPropInfo;
switch (uMsg) {
case WM_INITDIALOG:
//
// lParam points to PROPERTY_INFO structure which contains information
// the property whose valuse is to be viewed/modified. We store this
// pointer at DWLP_USER offset, so we get to it later.
//
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)lParam );
pPropInfo = (LPPROPERTY_INFO)lParam;
//
// Property name is the title of the dialog box.
//
SetWindowText( hwndDlg,
pPropInfo->lpszProperty );
//
// Show the property type.
//
SetWindowText( GetDlgItem(hwndDlg,
IDS_PROPERTY_TYPE),
pPropInfo->lpszType );
if ( DisplayArrayProperty(pPropInfo->lpszProperty,
pPropInfo->pvaValue,
hwndDlg) ) {
return TRUE;
}
EndDialog( hwndDlg, 0 );
case WM_COMMAND:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -