DWORD Size;
DWORD dwError;
-
// First check for a semi colon */
ptr = wcschr(ResourceDescriptor, L';');
if (ptr)
{
// This must be a dll resource based descriptor. Find the comma
ptr = wcschr(ResourceDescriptor, L',');
- if (ptr == NULL) return ERROR_INVALID_DATA;
+ if (ptr == NULL)
+ return ERROR_INVALID_DATA;
// Terminate the string where the comma was
*ptr = UNICODE_NULL;
// Expand any environment strings
Size = ExpandEnvironmentStringsW(&ResourceDescriptor[1], ModulePath, MAX_PATH);
- if (Size > MAX_PATH) return ERROR_BUFFER_OVERFLOW;
- if (Size == 0) return GetLastError();
+ if (Size > MAX_PATH)
+ return ERROR_BUFFER_OVERFLOW;
+ if (Size == 0)
+ return GetLastError();
// Put the comma back and move past it
*ptr = L',';
// Load the dll
hModule = LoadLibraryExW(ModulePath, NULL, LOAD_LIBRARY_AS_DATAFILE);
- if (hModule == NULL) return GetLastError();
+ if (hModule == NULL)
+ return GetLastError();
// Convert the resource id to a number
ResourceId = _wtoi(ptr);
// If the number is negative, make it positive
- if (ResourceId < 0) ResourceId = -ResourceId;
+ if (ResourceId < 0)
+ ResourceId = -ResourceId;
// Load the string from the dll
if (LoadStringW(hModule, ResourceId, ResString, 256))
size_t size = wcslen(Node.m_DeviceId) + 1;
m_DeviceId = new WCHAR[size];
StringCbCopyW(m_DeviceId, size * sizeof(WCHAR), Node.m_DeviceId);
-
}
CDeviceNode::~CDeviceNode()
// Now get the actual device id
cr = CM_Get_Device_IDW(m_DevInst,
- m_DeviceId,
- ulLength + 1,
- 0);
+ m_DeviceId,
+ ulLength + 1,
+ 0);
if (cr != CR_SUCCESS || wcscmp(m_DeviceId, L"HTREE\\ROOT\\0") == 0)
{
delete[] m_DeviceId;
m_DeviceId = NULL;
}
-
}
// Make sure we got the string
&m_DevinfoData);
}
-
// Check if the device has a problem
if (HasProblem())
{
}
}
-
-
-
// Get the class guid for this device
ulLength = MAX_GUID_STRING_LEN * sizeof(WCHAR);
cr = CM_Get_DevNode_Registry_PropertyW(m_DevInst,
m_ClassGuid = GUID_DEVCLASS_UNKNOWN;
}
-
// Get the image for the class this device is in
SetupDiGetClassImageIndex(m_ImageListData,
&m_ClassGuid,
&m_ClassImage);
-
// Get the description for the device
ulLength = DISPLAY_NAME_LEN * sizeof(WCHAR);
cr = CM_Get_DevNode_Registry_PropertyW(m_DevInst,
m_DisplayName,
&ulLength,
0);
-
}
if (cr != CR_SUCCESS)
pcp.StateChange = (Enable ? DICS_ENABLE : DICS_DISABLE);
pcp.HwProfile = 0;
-
// check both scopes to make sure we can make the change
for (int i = 0; i < 2; i++)
{
bool
CDeviceNode::UninstallDevice()
{
-
if (CanUninstall() == false)
return false;
// device and ask if they're happy with the uninstall
//
-
// Remove it
SetupDiSetClassInstallParamsW(m_hDevInfo,
&m_DevinfoData,
0);
return true;
-
}
/* PRIVATE METHODS ******************************************************/
}
DWORD
-CDeviceNode::GetFlags(
- )
+CDeviceNode::GetFlags()
{
SP_DEVINSTALL_PARAMS DevInstallParams;
DevInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
}
return false;
}
-
-
// Get the device image list
m_ImageListData.cbSize = sizeof(SP_CLASSIMAGELIST_DATA);
BOOL bSuccess = SetupDiGetClassImageList(&m_ImageListData);
- if (bSuccess == FALSE) return false;
+ if (bSuccess == FALSE)
+ return false;
// Create the main treeview
m_hTreeView = CreateWindowExW(WS_EX_CLIENTEDGE,
ThreadData->ScanForChanges = ScanForChanges;
ThreadData->UpdateView = UpdateView;
-
HANDLE hThread;
hThread = (HANDLE)_beginthreadex(NULL,
0,
cr = CM_Enumerate_Classes(ClassIndex,
ClassGuid,
0);
- if (cr != CR_SUCCESS) return false;
+ if (cr != CR_SUCCESS)
+ return false;
// Check if this is the unknown class
if (IsEqualGUID(*ClassGuid, GUID_DEVCLASS_UNKNOWN))
break;
}
-
This->SelectNode(LastSelectedNode);
delete ThreadData;
{
// Check if the parent device has anything at the same level
bSuccess = GetSiblingDevice(Device, &Device);
- if (bSuccess == FALSE) break;
+ if (bSuccess == FALSE)
+ break;
DeviceNode = dynamic_cast<CDeviceNode *>(GetDeviceNode(Device));
if (DeviceNode == nullptr)
}
// If there was a problem, expand the ancestors
- if (HasProblem) return false;
+ if (HasProblem)
+ return false;
return true;
}
)
{
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
- if (Node == nullptr) return false;
+ if (Node == nullptr)
+ return false;
if (Enable == false)
{
if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_DISABLE))
{
if (MessageBoxW(m_hMainWnd,
- str,
- Node->GetDisplayName(),
- MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
+ str,
+ Node->GetDisplayName(),
+ MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
{
return false;
}
)
{
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
- if (Node == nullptr) return false;
+ if (Node == nullptr)
+ return false;
DWORD dwReboot;
if (InstallDevInst(m_hMainWnd, Node->GetDeviceId(), TRUE, &dwReboot))
)
{
CDeviceNode *Node = dynamic_cast<CDeviceNode *>(GetSelectedNode());
- if (Node == nullptr) return false;
+ if (Node == nullptr)
+ return false;
CAtlStringW str;
if (str.LoadStringW(g_hThisInstance, IDS_CONFIRM_UNINSTALL))
{
if (MessageBoxW(m_hMainWnd,
- str,
- Node->GetDisplayName(),
- MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
+ str,
+ Node->GetDisplayName(),
+ MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2) != IDYES)
{
return false;
}
HMODULE hModule;
hModule = LoadLibraryW(L"hdwwiz.cpl");
- if (hModule == NULL) return false;
+ if (hModule == NULL)
+ return false;
pAddHardwareWizard = (PADDHARDWAREWIZARD)GetProcAddress(hModule,
"AddHardwareWizard");
// Check if this node has any children
hItem = TreeView_GetChild(m_hTreeView, hParentItem);
- if (hItem == NULL) return NULL;
+ if (hItem == NULL)
+ return NULL;
// The lParam contains the node pointer data
tvItem.hItem = hItem;
// This node may have its own children
FoundItem = RecurseFindDevice(hItem, Node);
- if (FoundItem) return FoundItem;
+ if (FoundItem)
+ return FoundItem;
// Loop all the siblings
for (;;)
{
// Get the next item at this level
hItem = TreeView_GetNextSibling(m_hTreeView, hItem);
- if (hItem == NULL) break;
+ if (hItem == NULL)
+ break;
// The lParam contains the node pointer data
tvItem.hItem = hItem;
// This node may have its own children
FoundItem = RecurseFindDevice(hItem, Node);
- if (FoundItem) return FoundItem;
+ if (FoundItem)
+ return FoundItem;
}
return hItem;
// Check if there are any items in the tree
hRoot = TreeView_GetRoot(m_hTreeView);
- if (hRoot == NULL) return;
+ if (hRoot == NULL)
+ return;
// If we don't want to set select a node, just select root
if (Node == nullptr || Node->GetNodeType() == RootNode)
CClassNode *Node = nullptr;
Pos = m_ClassNodeList.GetHeadPosition();
- if (Pos == NULL) return nullptr;
+ if (Pos == NULL)
+ return nullptr;
do
{
CDeviceNode *Node = nullptr;
Pos = m_DeviceNodeList.GetHeadPosition();
- if (Pos == NULL) return nullptr;
+ if (Pos == NULL)
+ return nullptr;
do
{
ClassIndex++;
} while (Success);
-
// Get all the devices on the local machine
hDevInfo = SetupDiGetClassDevsW(NULL,
0,
{
// Get the devinst for this device
Success = SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);
- if (Success == FALSE) break;
+ if (Success == FALSE)
+ break;
// create a new device node and add it to the list
DeviceNode = new CDeviceNode(DeviceInfoData.DevInst, &m_ImageListData);
{
ATLASSERT(FALSE);
}
-
}
SetupDiDestroyDeviceInfoList(hDevInfo);
{
}
-
bool
CDeviceManager::Create(_In_ HWND /*hWndParent*/,
_In_ HINSTANCE hInst,
}
-
/* PRIVATE METHODS **********************************************/
bool
// Get the menu item id
switch (Type)
{
- case DevicesByType: CheckId = IDC_DEVBYTYPE; break;
- case DevicesByConnection: CheckId = IDC_DEVBYCONN; break;
- case ResourcesByType: CheckId = IDC_RESBYTYPE; break;
- case ResourcesByConnection: CheckId = IDC_RESBYCONN; break;
- default: ATLASSERT(FALSE); break;
+ case DevicesByType:
+ CheckId = IDC_DEVBYTYPE;
+ break;
+
+ case DevicesByConnection:
+ CheckId = IDC_DEVBYCONN;
+ break;
+
+ case ResourcesByType:
+ CheckId = IDC_RESBYTYPE;
+ break;
+
+ case ResourcesByConnection:
+ CheckId = IDC_RESBYCONN;
+ break;
+
+ default:
+ ATLASSERT(FALSE);
+ break;
}
// Set the new check item
(HMENU)IDC_TOOLBAR,
g_hThisInstance,
NULL);
- if (m_hToolBar == NULL) return FALSE;
+ if (m_hToolBar == NULL)
+ return FALSE;
// Don't show clipped buttons
SendMessageW(m_hToolBar,
SendMessageW(m_hToolBar, TB_SETSTATE, IDC_DISABLE_DRV, MAKELPARAM(State, 0));
}
-
-
bool
CDeviceManager::StatusBarLoadString(_In_ HWND hStatusBar,
_In_ INT PartId,
}
break;
}
+
case WM_TIMER:
{
if (wParam == REFRESH_TIMER)
}
case WM_ACTIVATE:
+ {
if (LOWORD(hwnd))
This->OnActivate();
break;
+ }
case WM_DESTROY:
{
HBITMAP hRootImage;
hRootImage = LoadBitmapW(g_hThisInstance,
MAKEINTRESOURCEW(IDB_ROOT_IMAGE));
- if (hRootImage == NULL) return FALSE;
+ if (hRootImage == NULL)
+ return false;
// Add this bitmap to the device image list. This is a bit hacky, but it's safe
m_ClassImage = ImageList_Add(m_ImageListData->ImageList,
if (ListView_GetItemCount(hDriversListView) == 0)
{
- if(LoadStringW(hDllInstance, IDS_NODRIVERS, szBuffer, _countof(szBuffer)))
+ if (LoadStringW(hDllInstance, IDS_NODRIVERS, szBuffer, _countof(szBuffer)))
MessageBoxW(hwndDlg, szBuffer, dap->szDevName, MB_OK);
EndDialog(hwndDlg, IDCANCEL);
}