partly implemented DeviceProblemWizardA/W
Modified: trunk/reactos/lib/devmgr/En.rc
Modified: trunk/reactos/lib/devmgr/advprop.c
Modified: trunk/reactos/lib/devmgr/devmgr.xml
Added: trunk/reactos/lib/devmgr/devprblm.c
Modified: trunk/reactos/lib/devmgr/precomp.h
Modified: trunk/reactos/lib/devmgr/resource.h
Modified: trunk/reactos/lib/devmgr/stubs.c

Modified: trunk/reactos/lib/devmgr/En.rc
--- trunk/reactos/lib/devmgr/En.rc	2005-12-03 15:26:36 UTC (rev 19838)
+++ trunk/reactos/lib/devmgr/En.rc	2005-12-03 16:42:41 UTC (rev 19839)
@@ -17,6 +17,8 @@
     IDS_UNKNOWNDEVICE "Unknown device"
     IDS_NODRIVERLOADED "No drivers are installed for this device."
     IDS_DEVONPARENT "on %1"
+    IDS_TROUBLESHOOTDEV "&Troubleshoot..."
+    IDS_ENABLEDEV "E&nable Device"
 END
 
 STRINGTABLE
@@ -104,7 +106,7 @@
      EDITTEXT IDC_DEVLOCATION, 100, 67, 145, 12, NOT WS_TABSTOP | NOT WS_BORDER | ES_AUTOHSCROLL | ES_READONLY
      GROUPBOX "Device status", IDC_DEVSTATUSGROUP, 7, 83, 238, 100
      EDITTEXT IDC_DEVSTATUS, 14, 96, 224, 61, NOT WS_TABSTOP | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
-     PUSHBUTTON "&Troubleshoot...", IDC_TROUBLESHOOT, 148, 163, 90, 15
+     PUSHBUTTON "&Troubleshoot...", IDC_DEVPROBLEM, 148, 163, 90, 15
      LTEXT "&Device usage:", IDC_DEVUSAGELABEL, 7, 188, 222, 8, WS_DISABLED
      COMBOBOX IDC_DEVUSAGE, 7, 198, 239, 40, CBS_DROPDOWNLIST | WS_VSCROLL | WS_DISABLED
 END

Modified: trunk/reactos/lib/devmgr/advprop.c
--- trunk/reactos/lib/devmgr/advprop.c	2005-12-03 15:26:36 UTC (rev 19838)
+++ trunk/reactos/lib/devmgr/advprop.c	2005-12-03 16:42:41 UTC (rev 19839)
@@ -218,8 +218,10 @@
               IN BOOL ReOpen)
 {
     HICON hIcon;
-    HWND hDevUsage;
-    HWND hPropSheetDlg;
+    HWND hDevUsage, hPropSheetDlg, hDevProbBtn;
+    CONFIGRET cr;
+    ULONG Status, ProblemNumber;
+    UINT TroubleShootStrId = IDS_TROUBLESHOOTDEV;
     BOOL bFlag;
     DWORD i;
     HDEVINFO DeviceInfoSet = NULL;
@@ -458,6 +460,31 @@
                        dap->szTemp);
     }
 
+    /* set the device troubleshoot button text and disable it if necessary */
+    hDevProbBtn = GetDlgItem(hwndDlg,
+                             IDC_DEVPROBLEM);
+    EnableWindow(hDevProbBtn,
+                 dap->IsAdmin);
+    cr = CM_Get_DevNode_Status_Ex(&Status,
+                                  &ProblemNumber,
+                                  DeviceInfoData->DevInst,
+                                  0,
+                                  dap->hMachine);
+    if (cr == CR_SUCCESS &&
+        (Status & DN_HAS_PROBLEM) && ProblemNumber == CM_PROB_DISABLED)
+    {
+        TroubleShootStrId = IDS_ENABLEDEV;
+    }
+
+    if (LoadString(hDllInstance,
+                   TroubleShootStrId,
+                   dap->szTemp,
+                   sizeof(dap->szTemp) / sizeof(dap->szTemp[0])) != 0)
+    {
+        SetWindowText(hDevProbBtn,
+                      dap->szTemp);
+    }
+
     /* check if the device can be enabled/disabled */
     hDevUsage = GetDlgItem(hwndDlg,
                            IDC_DEVUSAGE);
@@ -579,6 +606,19 @@
                         }
                         break;
                     }
+
+                    case IDC_DEVPROBLEM:
+                    {
+                        if (dap->IsAdmin)
+                        {
+                            /* display the device problem wizard */
+                            ShowDeviceProblemWizard(hwndDlg,
+                                                    dap->DeviceInfoSet,
+                                                    &dap->DeviceInfoData,
+                                                    dap->hMachine);
+                        }
+                        break;
+                    }
                 }
                 break;
             }
@@ -959,6 +999,12 @@
     HINSTANCE hComCtl32;
     INT_PTR Ret = -1;
 
+    if (lpDeviceID == NULL)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     /* dynamically load comctl32 */
     hComCtl32 = LoadAndInitComctl32();
     if (hComCtl32 != NULL)
@@ -1072,7 +1118,8 @@
  * ARGUMENTS
  *   hWndParent:    Handle to the parent window
  *   lpMachineName: Machine Name, NULL is the local machine
- *   lpDeviceID:    Specifies the device whose properties are to be shown
+ *   lpDeviceID:    Specifies the device whose properties are to be shown, optional if
+ *                  bShowDevMgr is nonzero
  *   dwFlags:       This parameter can be a combination of the following flags:
  *                  * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
  *                                              the default device status action button
@@ -1150,7 +1197,8 @@
  * ARGUMENTS
  *   hWndParent:    Handle to the parent window
  *   lpMachineName: Machine Name, NULL is the local machine
- *   lpDeviceID:    Specifies the device whose properties are to be shown
+ *   lpDeviceID:    Specifies the device whose properties are to be shown, optional if
+ *                  bShowDevMgr is nonzero
  *   dwFlags:       This parameter can be a combination of the following flags:
  *                  * DPF_DEVICE_STATUS_ACTION: Only valid if bShowDevMgr, causes
  *                                              the default device status action button

Modified: trunk/reactos/lib/devmgr/devmgr.xml
--- trunk/reactos/lib/devmgr/devmgr.xml	2005-12-03 15:26:36 UTC (rev 19838)
+++ trunk/reactos/lib/devmgr/devmgr.xml	2005-12-03 16:42:41 UTC (rev 19839)
@@ -15,6 +15,7 @@
 	<library>user32</library>
 	<file>devmgr.rc</file>
 	<file>advprop.c</file>
+	<file>devprblm.c</file>
 	<file>hwpage.c</file>
 	<file>misc.c</file>
 	<file>stubs.c</file>

Added: trunk/reactos/lib/devmgr/devprblm.c
--- trunk/reactos/lib/devmgr/devprblm.c	2005-12-03 15:26:36 UTC (rev 19838)
+++ trunk/reactos/lib/devmgr/devprblm.c	2005-12-03 16:42:41 UTC (rev 19839)
@@ -0,0 +1,212 @@
+/*
+ * ReactOS Device Manager Applet
+ * Copyright (C) 2004 - 2005 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* $Id: hwpage.c 19599 2005-11-26 02:12:58Z weiden $
+ *
+ * PROJECT:         ReactOS devmgr.dll
+ * FILE:            lib/devmgr/devprblm.c
+ * PURPOSE:         ReactOS Device Manager
+ * PROGRAMMER:      Thomas Weidenmueller <w3seek@reactos.com>
+ * UPDATE HISTORY:
+ *      04-04-2004  Created
+ */
+#include <precomp.h>
+
+#define NDEBUG
+#include <debug.h>
+
+
+BOOL
+ShowDeviceProblemWizard(IN HWND hWndParent  OPTIONAL,
+                        IN HDEVINFO hDevInfo,
+                        IN PSP_DEVINFO_DATA DevInfoData,
+                        IN HMACHINE hMachine  OPTIONAL)
+{
+    CONFIGRET cr;
+    ULONG Status, ProblemNumber;
+    BOOL Ret = FALSE;
+
+    cr = CM_Get_DevNode_Status_Ex(&Status,
+                                  &ProblemNumber,
+                                  DevInfoData->DevInst,
+                                  0,
+                                  hMachine);
+    if (cr == CR_SUCCESS && (Status & DN_HAS_PROBLEM))
+    {
+        switch (ProblemNumber)
+        {
+            case CM_PROB_DISABLED:
+            {
+                /* FIXME - display the "Enable Device" wizard */
+                break;
+            }
+
+            default:
+            {
+                /* FIXME - troubleshoot the device */
+                break;
+            }
+        }
+    }
+
+    return Ret;
+}
+
+
+/***************************************************************************
+ * NAME                                                         EXPORTED
+ *      DeviceProblemWizardA
+ *
+ * DESCRIPTION
+ *   Calls the device problem wizard
+ *
+ * ARGUMENTS
+ *   hWndParent:    Handle to the parent window
+ *   lpMachineName: Machine Name, NULL is the local machine
+ *   lpDeviceID:    Specifies the device, also see NOTEs
+ *
+ * RETURN VALUE
+ *   TRUE:  if no errors occured
+ *   FALSE: if errors occured
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+DeviceProblemWizardA(IN HWND hWndParent  OPTIONAL,
+                     IN LPCSTR lpMachineName  OPTIONAL,
+                     IN LPCSTR lpDeviceID)
+{
+    LPWSTR lpMachineNameW = NULL;
+    LPWSTR lpDeviceIDW = NULL;
+    BOOL Ret = FALSE;
+
+    if (lpMachineName != NULL)
+    {
+        if (!(lpMachineNameW = ConvertMultiByteToUnicode(lpMachineName,
+                                                         CP_ACP)))
+        {
+            goto Cleanup;
+        }
+    }
+    if (lpDeviceID != NULL)
+    {
+        if (!(lpDeviceIDW = ConvertMultiByteToUnicode(lpDeviceID,
+                                                      CP_ACP)))
+        {
+            goto Cleanup;
+        }
+    }
+
+    Ret = DeviceProblemWizardW(hWndParent,
+                               lpMachineNameW,
+                               lpDeviceIDW);
+
+Cleanup:
+    if (lpMachineNameW != NULL)
+    {
+        HeapFree(GetProcessHeap(),
+                 0,
+                 lpMachineNameW);
+    }
+    if (lpDeviceIDW != NULL)
+    {
+        HeapFree(GetProcessHeap(),
+                 0,
+                 lpDeviceIDW);
+    }
+
+    return Ret;
+}
+
+
+/***************************************************************************
+ * NAME                                                         EXPORTED
+ *      DeviceProblemWizardW
+ *
+ * DESCRIPTION
+ *   Calls the device problem wizard
+ *
+ * ARGUMENTS
+ *   hWndParent:    Handle to the parent window
+ *   lpMachineName: Machine Name, NULL is the local machine
+ *   lpDeviceID:    Specifies the device, also see NOTEs
+ *
+ * RETURN VALUE
+ *   TRUE:  if no errors occured
+ *   FALSE: if errors occured
+ *
+ * @unimplemented
+ */
+BOOL
+WINAPI
+DeviceProblemWizardW(IN HWND hWndParent  OPTIONAL,
+                     IN LPCWSTR lpMachineName  OPTIONAL,
+                     IN LPCWSTR lpDeviceID)
+{
+    HDEVINFO hDevInfo;
+    SP_DEVINFO_DATA DevInfoData;
+    HINSTANCE hComCtl32;
+    CONFIGRET cr;
+    HMACHINE hMachine;
+    BOOL Ret = FALSE;
+
+    if (lpDeviceID == NULL)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    /* dynamically load comctl32 */
+    hComCtl32 = LoadAndInitComctl32();
+    if (hComCtl32 != NULL)
+    {
+        hDevInfo = SetupDiCreateDeviceInfoListEx(NULL,
+                                                 hWndParent,
+                                                 lpMachineName,
+                                                 NULL);
+        if (hDevInfo != INVALID_HANDLE_VALUE)
+        {
+            cr = CM_Connect_Machine(lpMachineName,
+                                    &hMachine);
+            if (cr == CR_SUCCESS)
+            {
+                DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+                if (SetupDiOpenDeviceInfo(hDevInfo,
+                                          lpDeviceID,
+                                          hWndParent,
+                                          0,
+                                          &DevInfoData))
+                {
+                    Ret = ShowDeviceProblemWizard(hWndParent,
+                                                  hDevInfo,
+                                                  &DevInfoData,
+                                                  hMachine);
+                }
+
+                CM_Disconnect_Machine(hMachine);
+            }
+
+            SetupDiDestroyDeviceInfoList(hDevInfo);
+        }
+
+        FreeLibrary(hComCtl32);
+    }
+
+    return Ret;
+}
Property changes on: trunk/reactos/lib/devmgr/devprblm.c
___________________________________________________________________
Name: svn:keywords
   + author date revision
Name: svn:eol-style
   + native

Modified: trunk/reactos/lib/devmgr/precomp.h
--- trunk/reactos/lib/devmgr/precomp.h	2005-12-03 15:26:36 UTC (rev 19838)
+++ trunk/reactos/lib/devmgr/precomp.h	2005-12-03 16:42:41 UTC (rev 19839)
@@ -71,18 +71,18 @@
                    LPWSTR lpString,
                    UINT uMaxString);
 
-WINBOOL
+BOOL
 WINAPI
-DeviceProblemWizardA(HWND hWndParent,
-                     LPCSTR lpMachineName,
-                     LPCSTR lpDeviceID);
+DeviceProblemWizardA(IN HWND hWndParent  OPTIONAL,
+                     IN LPCSTR lpMachineName  OPTIONAL,
+                     IN LPCSTR lpDeviceID);
 
 
-WINBOOL
+BOOL
 WINAPI
-DeviceProblemWizardW(HWND hWndParent,
-                     LPCWSTR lpMachineName,
-                     LPCWSTR lpDeviceID);
+DeviceProblemWizardW(IN HWND hWndParent  OPTIONAL,
+                     IN LPCWSTR lpMachineName  OPTIONAL,
+                     IN LPCWSTR lpDeviceID);
 
 VOID
 WINAPI
@@ -200,6 +200,14 @@
                                 IN LPCWSTR lpMachineName,
                                 IN DWORD dwFlags);
 
+/* DEVPRBLM.C */
+
+BOOL
+ShowDeviceProblemWizard(IN HWND hWndParent  OPTIONAL,
+                        IN HDEVINFO hDevInfo,
+                        IN PSP_DEVINFO_DATA DevInfoData,
+                        IN HMACHINE hMachine  OPTIONAL);
+
 /* MISC.C */
 
 DWORD

Modified: trunk/reactos/lib/devmgr/resource.h
--- trunk/reactos/lib/devmgr/resource.h	2005-12-03 15:26:36 UTC (rev 19838)
+++ trunk/reactos/lib/devmgr/resource.h	2005-12-03 16:42:41 UTC (rev 19839)
@@ -23,8 +23,8 @@
 #define IDC_TROUBLESHOOT	0x589
 #define IDC_PROPERTIES		0x58A
 #define IDC_DEVUSAGELABEL	0x58B
+#define IDC_DEVPROBLEM		0x58C
 
-
 #define IDS_NAME		0x100
 #define IDS_TYPE		0x101
 #define IDS_MANUFACTURER	0x102
@@ -38,6 +38,8 @@
 #define IDS_UNKNOWNDEVICE	0x10A
 #define IDS_NODRIVERLOADED	0x10B
 #define IDS_DEVONPARENT		0x10C
+#define IDS_TROUBLESHOOTDEV	0x10D
+#define IDS_ENABLEDEV		0x10E
 
 #define IDS_DEV_NO_PROBLEM			0x200
 #define IDS_DEV_NOT_CONFIGURED			0x201

Modified: trunk/reactos/lib/devmgr/stubs.c
--- trunk/reactos/lib/devmgr/stubs.c	2005-12-03 15:26:36 UTC (rev 19838)
+++ trunk/reactos/lib/devmgr/stubs.c	2005-12-03 16:42:41 UTC (rev 19839)
@@ -318,72 +318,6 @@
 
 /***************************************************************************
  * NAME                                                         EXPORTED
- *      DeviceProblemWizardA
- *
- * DESCRIPTION
- *   Calls the device problem wizard
- *
- * ARGUMENTS
- *   hWndParent:    Handle to the parent window
- *   lpMachineName: Machine Name, NULL is the local machine
- *   lpDeviceID:    Specifies the device, also see NOTEs
- *
- * RETURN VALUE
- *   TRUE:  if no errors occured
- *   FALSE: if errors occured
- *
- * REVISIONS
- *
- * NOTE
- *
- * @unimplemented
- */
-WINBOOL
-WINAPI
-DeviceProblemWizardA(HWND hWndParent,
-                     LPCSTR lpMachineName,
-                     LPCSTR lpDeviceID)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/***************************************************************************
- * NAME                                                         EXPORTED
- *      DeviceProblemWizardW
- *
- * DESCRIPTION
- *   Calls the device problem wizard
- *
- * ARGUMENTS
- *   hWndParent:    Handle to the parent window
- *   lpMachineName: Machine Name, NULL is the local machine
- *   lpDeviceID:    Specifies the device, also see NOTEs
- *
- * RETURN VALUE
- *   TRUE:  if no errors occured
- *   FALSE: if errors occured
- *
- * REVISIONS
- *
- * NOTE
- *
- * @unimplemented
- */
-WINBOOL
-WINAPI
-DeviceProblemWizardW(HWND hWndParent,
-                     LPCWSTR lpMachineName,
-                     LPCWSTR lpDeviceID)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/***************************************************************************
- * NAME                                                         EXPORTED
  *      DeviceProblemWizard_RunDLLA
  *
  * DESCRIPTION