ReactOS 0.4.16-dev-2104-gb84fa49
newdev.c File Reference
#include "newdev_private.h"
#include <stdio.h>
#include <winnls.h>
Include dependency graph for newdev.c:

Go to the source code of this file.

Functions

static BOOL SearchDriver (IN PDEVINSTDATA DevInstData, IN LPCWSTR Directory OPTIONAL, IN LPCWSTR InfFile OPTIONAL)
 
BOOL WINAPI UpdateDriverForPlugAndPlayDevicesW (IN HWND hwndParent, IN LPCWSTR HardwareId, IN LPCWSTR FullInfPath, IN DWORD InstallFlags, OUT PBOOL bRebootRequired OPTIONAL)
 
BOOL WINAPI UpdateDriverForPlugAndPlayDevicesA (IN HWND hwndParent, IN LPCSTR HardwareId, IN LPCSTR FullInfPath, IN DWORD InstallFlags, OUT PBOOL bRebootRequired OPTIONAL)
 
static BOOL IsDots (IN LPCWSTR str)
 
static LPCWSTR GetFileExt (IN LPWSTR FileName)
 
static BOOL SearchDriverRecursive (IN PDEVINSTDATA DevInstData, IN LPCWSTR Path)
 
BOOL CheckBestDriver (_In_ PDEVINSTDATA DevInstData, _In_ PCWSTR pszDir)
 
BOOL ScanFoldersForDriver (IN PDEVINSTDATA DevInstData)
 
BOOL PrepareFoldersToScan (IN PDEVINSTDATA DevInstData, IN BOOL IncludeRemovableDevices, IN BOOL IncludeCustomPath, IN HWND hwndCombo OPTIONAL)
 
BOOL InstallCurrentDriver (IN PDEVINSTDATA DevInstData)
 
BOOL WINAPI DevInstallW (IN HWND hWndParent, IN HINSTANCE hInstance, IN LPCWSTR InstanceId, IN INT Show)
 
BOOL WINAPI InstallDevInstEx (IN HWND hWndParent, IN LPCWSTR InstanceId, IN BOOL bUpdate, OUT LPDWORD lpReboot, IN DWORD Unknown)
 
BOOL WINAPI InstallDevInst (IN HWND hWndParent, IN LPCWSTR InstanceId, IN BOOL bUpdate, OUT LPDWORD lpReboot)
 
BOOL WINAPI ClientSideInstallW (IN HWND hWndOwner, IN HINSTANCE hInstance, IN LPWSTR lpNamedPipeName, IN INT Show)
 
BOOL WINAPI DllMain (IN HINSTANCE hInstance, IN DWORD dwReason, IN LPVOID lpReserved)
 

Variables

HINSTANCE hDllInstance
 

Function Documentation

◆ CheckBestDriver()

BOOL CheckBestDriver ( _In_ PDEVINSTDATA  DevInstData,
_In_ PCWSTR  pszDir 
)

Definition at line 420 of file newdev.c.

423{
424 return SearchDriverRecursive(DevInstData, pszDir);
425}
static BOOL SearchDriverRecursive(IN PDEVINSTDATA DevInstData, IN LPCWSTR Path)
Definition: newdev.c:350
_In_ LPCSTR pszDir
Definition: shellapi.h:601

Referenced by BrowseCallbackProc().

◆ ClientSideInstallW()

BOOL WINAPI ClientSideInstallW ( IN HWND  hWndOwner,
IN HINSTANCE  hInstance,
IN LPWSTR  lpNamedPipeName,
IN INT  Show 
)

Definition at line 960 of file newdev.c.

965{
967 BOOL ShowWizard;
969 DWORD Value;
972 PWSTR InstallEventName = NULL;
974
975 /* Open the pipe */
976 hPipe = CreateFileW(lpNamedPipeName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
977
978 if(hPipe == INVALID_HANDLE_VALUE)
979 {
980 ERR("CreateFileW failed with error %u\n", GetLastError());
981 goto cleanup;
982 }
983
984 /* Read the data. Some is just included for compatibility with Windows right now and not yet used by ReactOS.
985 See umpnpmgr for more details. */
986 if(!ReadFile(hPipe, &Value, sizeof(Value), &BytesRead, NULL))
987 {
988 ERR("ReadFile failed with error %u\n", GetLastError());
989 goto cleanup;
990 }
991
992 InstallEventName = (PWSTR)HeapAlloc(GetProcessHeap(), 0, Value);
993
994 if(!ReadFile(hPipe, InstallEventName, Value, &BytesRead, NULL))
995 {
996 ERR("ReadFile failed with error %u\n", GetLastError());
997 goto cleanup;
998 }
999
1000 /* I couldn't figure out what the following value means under Windows XP.
1001 Therefore I used it in umpnpmgr to pass the ShowWizard variable. */
1002 if(!ReadFile(hPipe, &ShowWizard, sizeof(ShowWizard), &BytesRead, NULL))
1003 {
1004 ERR("ReadFile failed with error %u\n", GetLastError());
1005 goto cleanup;
1006 }
1007
1008 /* Next one is again size in bytes of the following string */
1009 if(!ReadFile(hPipe, &Value, sizeof(Value), &BytesRead, NULL))
1010 {
1011 ERR("ReadFile failed with error %u\n", GetLastError());
1012 goto cleanup;
1013 }
1014
1016
1017 if(!ReadFile(hPipe, DeviceInstance, Value, &BytesRead, NULL))
1018 {
1019 ERR("ReadFile failed with error %u\n", GetLastError());
1020 goto cleanup;
1021 }
1022
1024 if(!ReturnValue)
1025 {
1026 ERR("DevInstallW failed with error %lu\n", GetLastError());
1027 goto cleanup;
1028 }
1029
1030 hInstallEvent = CreateEventW(NULL, TRUE, FALSE, InstallEventName);
1031 if(!hInstallEvent)
1032 {
1033 TRACE("CreateEventW('%ls') failed with error %lu\n", InstallEventName, GetLastError());
1034 goto cleanup;
1035 }
1036
1039
1040cleanup:
1041 if(hPipe != INVALID_HANDLE_VALUE)
1042 CloseHandle(hPipe);
1043
1044 if(InstallEventName)
1045 HeapFree(GetProcessHeap(), 0, InstallEventName);
1046
1047 if(DeviceInstance)
1049
1050 return ReturnValue;
1051}
UINT32 void void ** ReturnValue
Definition: acevents.h:216
HANDLE hInstallEvent
Definition: install.c:40
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define GENERIC_READ
Definition: compat.h:135
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
static void cleanup(void)
Definition: main.c:1335
static const WCHAR DeviceInstance[]
Definition: interface.c:28
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DevInstallW(IN HWND hWndParent, IN HINSTANCE hInstance, IN LPCWSTR InstanceId, IN INT Show)
Definition: newdev.c:657
#define TRACE(s)
Definition: solgame.cpp:4
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
uint16_t * PWSTR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SW_HIDE
Definition: winuser.h:779
#define SW_SHOWNOACTIVATE
Definition: winuser.h:785

◆ DevInstallW()

BOOL WINAPI DevInstallW ( IN HWND  hWndParent,
IN HINSTANCE  hInstance,
IN LPCWSTR  InstanceId,
IN INT  Show 
)

Definition at line 657 of file newdev.c.

662{
663 PDEVINSTDATA DevInstData = NULL;
664 BOOL ret;
665 DWORD config_flags;
666 BOOL retval = FALSE;
667
668 TRACE("(%p, %p, %s, %d)\n", hWndParent, hInstance, debugstr_w(InstanceId), Show);
669
670 if (!IsUserAdmin())
671 {
672 /* XP kills the process... */
674 }
675
676 DevInstData = HeapAlloc(GetProcessHeap(), 0, sizeof(DEVINSTDATA));
677 if (!DevInstData)
678 {
679 TRACE("HeapAlloc() failed\n");
681 goto cleanup;
682 }
683
684 /* Clear devinst data */
685 ZeroMemory(DevInstData, sizeof(DEVINSTDATA));
686 DevInstData->devInfoData.cbSize = 0; /* Tell if the devInfoData is valid */
687
688 /* Fill devinst data */
690 if (DevInstData->hDevInfo == INVALID_HANDLE_VALUE)
691 {
692 TRACE("SetupDiCreateDeviceInfoListExW() failed with error 0x%x\n", GetLastError());
693 goto cleanup;
694 }
695
696 DevInstData->devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
698 DevInstData->hDevInfo,
700 NULL,
701 0, /* Open flags */
702 &DevInstData->devInfoData);
703 if (!ret)
704 {
705 TRACE("SetupDiOpenDeviceInfoW() failed with error 0x%x (InstanceId %s)\n",
707 DevInstData->devInfoData.cbSize = 0;
708 goto cleanup;
709 }
710
713 DevInstData->hDevInfo,
714 &DevInstData->devInfoData,
716 &DevInstData->regDataType,
717 NULL, 0,
718 &DevInstData->requiredSize);
719
720 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER && DevInstData->regDataType == REG_SZ)
721 {
722 DevInstData->buffer = HeapAlloc(GetProcessHeap(), 0, DevInstData->requiredSize);
723 if (!DevInstData->buffer)
724 {
725 TRACE("HeapAlloc() failed\n");
727 }
728 else
729 {
731 DevInstData->hDevInfo,
732 &DevInstData->devInfoData,
734 &DevInstData->regDataType,
735 DevInstData->buffer, DevInstData->requiredSize,
736 &DevInstData->requiredSize);
737 }
738 }
739 if (!ret)
740 {
741 TRACE("SetupDiGetDeviceRegistryProperty() failed with error 0x%x (InstanceId %s)\n",
743 goto cleanup;
744 }
745
747 DevInstData->hDevInfo,
748 &DevInstData->devInfoData,
750 NULL,
751 (BYTE *)&config_flags,
752 sizeof(config_flags),
753 NULL))
754 {
755 if (config_flags & CONFIGFLAG_FAILEDINSTALL)
756 {
757 /* The device is disabled */
758 TRACE("Device is disabled\n");
759 retval = TRUE;
760 goto cleanup;
761 }
762 }
763
764 TRACE("Installing %s (%s)\n", debugstr_w((PCWSTR)DevInstData->buffer), debugstr_w(InstanceId));
765
766 /* Search driver in default location and removable devices */
767 if (!PrepareFoldersToScan(DevInstData, FALSE, FALSE, NULL))
768 {
769 TRACE("PrepareFoldersToScan() failed with error 0x%lx\n", GetLastError());
770 goto cleanup;
771 }
772 if (ScanFoldersForDriver(DevInstData))
773 {
774 /* Driver found ; install it */
775 retval = InstallCurrentDriver(DevInstData);
776 TRACE("InstallCurrentDriver() returned %d\n", retval);
777 if (retval && Show != SW_HIDE)
778 {
779 /* Should we display the 'Need to reboot' page? */
780 SP_DEVINSTALL_PARAMS installParams;
781 installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
783 DevInstData->hDevInfo,
784 &DevInstData->devInfoData,
785 &installParams))
786 {
787 if (installParams.Flags & (DI_NEEDRESTART | DI_NEEDREBOOT))
788 {
789 TRACE("Displaying 'Reboot' wizard page\n");
791 }
792 }
793 }
794 goto cleanup;
795 }
796 else if (Show == SW_HIDE)
797 {
798 /* We can't show the wizard. Fail the install */
799 TRACE("No wizard\n");
800 goto cleanup;
801 }
802
803 /* Prepare the wizard, and display it */
804 TRACE("Need to show install wizard\n");
806
807cleanup:
808 if (DevInstData)
809 {
810 if (DevInstData->devInfoData.cbSize != 0)
811 {
812 if (!SetupDiDestroyDriverInfoList(DevInstData->hDevInfo, &DevInstData->devInfoData, SPDIT_COMPATDRIVER))
813 TRACE("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
814 }
815 if (DevInstData->hDevInfo != INVALID_HANDLE_VALUE)
816 {
817 if (!SetupDiDestroyDeviceInfoList(DevInstData->hDevInfo))
818 TRACE("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
819 }
820 HeapFree(GetProcessHeap(), 0, DevInstData->buffer);
821 HeapFree(GetProcessHeap(), 0, DevInstData);
822 }
823
824 return retval;
825}
HINSTANCE hInstance
Definition: charmap.c:19
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1489
#define IDD_WELCOMEPAGE
Definition: resource.h:21
#define IDD_NEEDREBOOT
Definition: resource.h:27
HDEVINFO WINAPI SetupDiCreateDeviceInfoListExW(const GUID *ClassGuid, HWND hwndParent, PCWSTR MachineName, PVOID Reserved)
Definition: devinst.c:1259
BOOL WINAPI SetupDiGetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, PDWORD PropertyRegDataType, PBYTE PropertyBuffer, DWORD PropertyBufferSize, PDWORD RequiredSize)
Definition: devinst.c:3224
BOOL WINAPI SetupDiOpenDeviceInfoW(IN HDEVINFO DeviceInfoSet, IN PCWSTR DeviceInstanceId, IN HWND hwndParent OPTIONAL, IN DWORD OpenFlags, OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
Definition: devinst.c:4774
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
BOOL WINAPI SetupDiDestroyDriverInfoList(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN DWORD DriverType)
Definition: driver.c:1208
return ret
Definition: mutex.c:146
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:908
#define debugstr_w
Definition: kernel32.h:32
#define REG_SZ
Definition: layer.c:22
#define ZeroMemory
Definition: minwinbase.h:31
static BOOL IsUserAdmin(VOID)
Definition: netid.c:163
BOOL ScanFoldersForDriver(IN PDEVINSTDATA DevInstData)
Definition: newdev.c:428
BOOL PrepareFoldersToScan(IN PDEVINSTDATA DevInstData, IN BOOL IncludeRemovableDevices, IN BOOL IncludeCustomPath, IN HWND hwndCombo OPTIONAL)
Definition: newdev.c:463
BOOL InstallCurrentDriver(IN PDEVINSTDATA DevInstData)
Definition: newdev.c:541
BOOL DisplayWizard(IN PDEVINSTDATA DevInstData, IN HWND hwndParent, IN UINT startPage)
Definition: wizard.c:1372
#define CONFIGFLAG_FAILEDINSTALL
Definition: regstr.h:396
#define DI_NEEDRESTART
Definition: setupapi.h:53
#define SPDRP_DEVICEDESC
Definition: setupapi.h:508
#define SetupDiGetDeviceInstallParams
Definition: setupapi.h:2600
SP_DEVINSTALL_PARAMS_A SP_DEVINSTALL_PARAMS
Definition: setupapi.h:1156
#define SetupDiGetDeviceRegistryProperty
Definition: setupapi.h:2604
#define DI_NEEDREBOOT
Definition: setupapi.h:54
struct _SP_DEVINFO_DATA SP_DEVINFO_DATA
#define SPDRP_CONFIGFLAGS
Definition: setupapi.h:518
#define SPDIT_COMPATDRIVER
Definition: setupapi.h:507
SP_DEVINFO_DATA devInfoData
HDEVINFO hDevInfo
DWORD requiredSize
const uint16_t * PCWSTR
Definition: typedefs.h:57
int retval
Definition: wcstombs.cpp:91
#define ERROR_GEN_FAILURE
Definition: winerror.h:256
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ClientSideInstallW().

◆ DllMain()

BOOL WINAPI DllMain ( IN HINSTANCE  hInstance,
IN DWORD  dwReason,
IN LPVOID  lpReserved 
)

@DllMain

Core routine of the Utility Manager's library.

Parameters
[in]hDllInstanceThe entry point instance of the library.
[in]fdwReasonThe reason argument to indicate the motive DllMain is being called.
[in]lpvReservedReserved.
Returns
Returns TRUE when main call initialization has succeeded, FALSE otherwise.

Definition at line 1054 of file newdev.c.

1058{
1060 {
1062
1064
1065 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
1069 }
1070
1071 return TRUE;
1072}
DWORD dwReason
Definition: misc.cpp:135
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:904
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
static VOID InitControls(HWND hwnd)
Definition: mplay32.c:303
HINSTANCE hDllInstance
Definition: newdev.c:29
struct tagINITCOMMONCONTROLSEX INITCOMMONCONTROLSEX
#define ICC_PROGRESS_CLASS
Definition: commctrl.h:63

◆ GetFileExt()

static LPCWSTR GetFileExt ( IN LPWSTR  FileName)
static

Definition at line 338 of file newdev.c.

339{
340 LPCWSTR Dot;
341
342 Dot = wcsrchr(FileName, '.');
343 if (!Dot)
344 return L"";
345
346 return Dot;
347}
#define wcsrchr
Definition: compat.h:16
#define L(x)
Definition: resources.c:13
#define Dot(u, v)
Definition: normal.c:49
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by SearchDriverRecursive().

◆ InstallCurrentDriver()

BOOL InstallCurrentDriver ( IN PDEVINSTDATA  DevInstData)

Definition at line 541 of file newdev.c.

543{
544 BOOL ret;
545
546 TRACE("Installing driver %s: %s\n",
547 debugstr_w(DevInstData->drvInfoData.MfgName),
548 debugstr_w(DevInstData->drvInfoData.Description));
549
552 DevInstData->hDevInfo,
553 &DevInstData->devInfoData);
554 if (!ret)
555 {
556 TRACE("SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV) failed with error 0x%x\n", GetLastError());
557 return FALSE;
558 }
559
562 DevInstData->hDevInfo,
563 &DevInstData->devInfoData);
564 if (!ret)
565 {
566 TRACE("SetupDiCallClassInstaller(DIF_ALLOW_INSTALL) failed with error 0x%x\n", GetLastError());
567 return FALSE;
568 }
569
572 DevInstData->hDevInfo,
573 &DevInstData->devInfoData);
574 if (!ret)
575 {
576 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_PREANALYZE) failed with error 0x%x\n", GetLastError());
577 return FALSE;
578 }
579
582 DevInstData->hDevInfo,
583 &DevInstData->devInfoData);
584 if (!ret)
585 {
586 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_POSTANALYZE) failed with error 0x%x\n", GetLastError());
587 return FALSE;
588 }
589
592 DevInstData->hDevInfo,
593 &DevInstData->devInfoData);
594 if (!ret)
595 {
596 TRACE("SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES) failed with error 0x%x\n", GetLastError());
597 return FALSE;
598 }
599
602 DevInstData->hDevInfo,
603 &DevInstData->devInfoData);
604 if (!ret)
605 {
606 TRACE("SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS) failed with error 0x%x\n", GetLastError());
607 return FALSE;
608 }
609
612 DevInstData->hDevInfo,
613 &DevInstData->devInfoData);
614 if (!ret)
615 {
616 TRACE("SetupDiCallClassInstaller(DIF_INSTALLINTERFACES) failed with error 0x%x\n", GetLastError());
617 return FALSE;
618 }
619
622 DevInstData->hDevInfo,
623 &DevInstData->devInfoData);
624 if (!ret)
625 {
626 TRACE("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed with error 0x%x\n", GetLastError());
627 return FALSE;
628 }
629
632 DevInstData->hDevInfo,
633 &DevInstData->devInfoData);
634 if (!ret)
635 {
636 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_FINISHINSTALL) failed with error 0x%x\n", GetLastError());
637 return FALSE;
638 }
639
642 DevInstData->hDevInfo,
643 &DevInstData->devInfoData);
644 if (!ret)
645 {
646 TRACE("SetupDiCallClassInstaller(DIF_DESTROYPRIVATEDATA) failed with error 0x%x\n", GetLastError());
647 return FALSE;
648 }
649
650 return TRUE;
651}
BOOL WINAPI SetupDiCallClassInstaller(DI_FUNCTION InstallFunction, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:4024
#define DIF_INSTALLDEVICEFILES
Definition: setupapi.h:141
#define DIF_REGISTER_COINSTALLERS
Definition: setupapi.h:154
#define DIF_INSTALLINTERFACES
Definition: setupapi.h:152
#define DIF_NEWDEVICEWIZARD_PREANALYZE
Definition: setupapi.h:148
#define DIF_INSTALLDEVICE
Definition: setupapi.h:122
#define DIF_ALLOW_INSTALL
Definition: setupapi.h:144
#define DIF_DESTROYPRIVATEDATA
Definition: setupapi.h:132
#define DIF_SELECTBESTCOMPATDRV
Definition: setupapi.h:143
#define DIF_NEWDEVICEWIZARD_POSTANALYZE
Definition: setupapi.h:149
#define DIF_NEWDEVICEWIZARD_FINISHINSTALL
Definition: setupapi.h:150

Referenced by DevInstallW(), InstallDriverProc(), and UpdateDriverForPlugAndPlayDevicesW().

◆ InstallDevInst()

BOOL WINAPI InstallDevInst ( IN HWND  hWndParent,
IN LPCWSTR  InstanceId,
IN BOOL  bUpdate,
OUT LPDWORD  lpReboot 
)

Definition at line 946 of file newdev.c.

951{
952 return InstallDevInstEx(hWndParent, InstanceId, bUpdate, lpReboot, 0);
953}
BOOL WINAPI InstallDevInstEx(IN HWND hWndParent, IN LPCWSTR InstanceId, IN BOOL bUpdate, OUT LPDWORD lpReboot, IN DWORD Unknown)
Definition: newdev.c:830

Referenced by ShowDeviceProblemWizard(), UpdateDriver(), and CDeviceView::UpdateSelectedDevice().

◆ InstallDevInstEx()

BOOL WINAPI InstallDevInstEx ( IN HWND  hWndParent,
IN LPCWSTR  InstanceId,
IN BOOL  bUpdate,
OUT LPDWORD  lpReboot,
IN DWORD  Unknown 
)

Definition at line 830 of file newdev.c.

836{
837 PDEVINSTDATA DevInstData = NULL;
838 BOOL ret;
839 BOOL retval = FALSE;
840
841 TRACE("InstllDevInstEx(%p, %s, %d, %p, %lx)\n",
842 hWndParent, debugstr_w(InstanceId), bUpdate, lpReboot, Unknown);
843
844 DevInstData = HeapAlloc(GetProcessHeap(), 0, sizeof(DEVINSTDATA));
845 if (!DevInstData)
846 {
847 TRACE("HeapAlloc() failed\n");
849 goto cleanup;
850 }
851
852 /* Clear devinst data */
853 ZeroMemory(DevInstData, sizeof(DEVINSTDATA));
854 DevInstData->devInfoData.cbSize = 0; /* Tell if the devInfoData is valid */
855 DevInstData->bUpdate = bUpdate;
856
857 /* Fill devinst data */
859 if (DevInstData->hDevInfo == INVALID_HANDLE_VALUE)
860 {
861 TRACE("SetupDiCreateDeviceInfoListExW() failed with error 0x%x\n", GetLastError());
862 goto cleanup;
863 }
864
865 DevInstData->devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
867 DevInstData->hDevInfo,
869 NULL,
870 0, /* Open flags */
871 &DevInstData->devInfoData);
872 if (!ret)
873 {
874 TRACE("SetupDiOpenDeviceInfoW() failed with error 0x%x (InstanceId %s)\n",
876 DevInstData->devInfoData.cbSize = 0;
877 goto cleanup;
878 }
879
882 DevInstData->hDevInfo,
883 &DevInstData->devInfoData,
885 &DevInstData->regDataType,
886 NULL, 0,
887 &DevInstData->requiredSize);
888
889 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER && DevInstData->regDataType == REG_SZ)
890 {
891 DevInstData->buffer = HeapAlloc(GetProcessHeap(), 0, DevInstData->requiredSize);
892 if (!DevInstData->buffer)
893 {
894 TRACE("HeapAlloc() failed\n");
896 }
897 else
898 {
900 DevInstData->hDevInfo,
901 &DevInstData->devInfoData,
903 &DevInstData->regDataType,
904 DevInstData->buffer, DevInstData->requiredSize,
905 &DevInstData->requiredSize);
906 }
907 }
908
909 if (!ret)
910 {
911 TRACE("SetupDiGetDeviceRegistryProperty() failed with error 0x%x (InstanceId %s)\n",
913 goto cleanup;
914 }
915
916 /* Prepare the wizard, and display it */
917 TRACE("Need to show install wizard\n");
919
920cleanup:
921 if (DevInstData)
922 {
923 if (DevInstData->devInfoData.cbSize != 0)
924 {
925 if (!SetupDiDestroyDriverInfoList(DevInstData->hDevInfo, &DevInstData->devInfoData, SPDIT_COMPATDRIVER))
926 TRACE("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
927 }
928 if (DevInstData->hDevInfo != INVALID_HANDLE_VALUE)
929 {
930 if (!SetupDiDestroyDeviceInfoList(DevInstData->hDevInfo))
931 TRACE("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
932 }
933 HeapFree(GetProcessHeap(), 0, DevInstData->buffer);
934 HeapFree(GetProcessHeap(), 0, DevInstData);
935 }
936
937 return retval;
938}
@ Unknown
Definition: i8042prt.h:114

Referenced by InstallDevInst().

◆ IsDots()

static BOOL IsDots ( IN LPCWSTR  str)
static

Definition at line 331 of file newdev.c.

332{
333 if(wcscmp(str, L".") && wcscmp(str, L"..")) return FALSE;
334 return TRUE;
335}
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1972
const WCHAR * str

Referenced by SearchDriverRecursive().

◆ PrepareFoldersToScan()

BOOL PrepareFoldersToScan ( IN PDEVINSTDATA  DevInstData,
IN BOOL  IncludeRemovableDevices,
IN BOOL  IncludeCustomPath,
IN HWND hwndCombo  OPTIONAL 
)

Definition at line 463 of file newdev.c.

468{
469 WCHAR drive[] = {'?',':',0};
470 DWORD dwDrives = 0;
471 DWORD i;
472 UINT nType;
473 DWORD CustomTextLength = 0;
476 INT idx = (INT)SendMessageW(hwndCombo, CB_GETCURSEL, 0, 0);
477
478 /* Calculate length needed to store the search paths */
479 if (IncludeRemovableDevices)
480 {
481 dwDrives = GetLogicalDrives();
482 for (drive[0] = 'A', i = 1; drive[0] <= 'Z'; drive[0]++, i <<= 1)
483 {
484 if (dwDrives & i)
485 {
486 nType = GetDriveTypeW(drive);
487 if (nType == DRIVE_REMOVABLE || nType == DRIVE_CDROM)
488 {
489 LengthNeeded += 3;
490 }
491 }
492 }
493 }
494 if (IncludeCustomPath)
495 {
496 CustomTextLength = 1 + ((idx != CB_ERR) ?
497 (INT)SendMessageW(hwndCombo, CB_GETLBTEXTLEN, idx, 0) : ComboBox_GetTextLength(hwndCombo));
498 LengthNeeded += CustomTextLength;
499 }
500
501 /* Allocate space for search paths */
502 HeapFree(GetProcessHeap(), 0, DevInstData->CustomSearchPath);
503 DevInstData->CustomSearchPath = Buffer = HeapAlloc(
505 0,
506 (LengthNeeded + 1) * sizeof(WCHAR));
507 if (!Buffer)
508 {
509 TRACE("HeapAlloc() failed\n");
511 return FALSE;
512 }
513
514 /* Fill search paths */
515 if (IncludeRemovableDevices)
516 {
517 for (drive[0] = 'A', i = 1; drive[0] <= 'Z'; drive[0]++, i <<= 1)
518 {
519 if (dwDrives & i)
520 {
521 nType = GetDriveTypeW(drive);
522 if (nType == DRIVE_REMOVABLE || nType == DRIVE_CDROM)
523 {
524 Buffer += 1 + swprintf(Buffer, drive);
525 }
526 }
527 }
528 }
529 if (IncludeCustomPath)
530 {
531 Buffer += 1 + ((idx != CB_ERR) ?
532 SendMessageW(hwndCombo, CB_GETLBTEXT, idx, (LPARAM)Buffer) :
533 GetWindowTextW(hwndCombo, Buffer, CustomTextLength));
534 }
535 *Buffer = '\0';
536
537 return TRUE;
538}
Definition: bufpool.h:45
unsigned int idx
Definition: utils.c:41
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
DWORD WINAPI DECLSPEC_HOTPATCH GetLogicalDrives(void)
Definition: volume.c:513
#define swprintf
Definition: precomp.h:40
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ SECURITY_INFORMATION _In_ ULONG _Out_opt_ PULONG LengthNeeded
Definition: fltkernel.h:1343
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DRIVE_CDROM
Definition: machpc98.h:119
LONG_PTR LPARAM
Definition: minwindef.h:175
unsigned int UINT
Definition: ndis.h:50
#define INT
Definition: polytest.cpp:20
int32_t INT
Definition: typedefs.h:58
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1382
#define DRIVE_REMOVABLE
Definition: winbase.h:275
#define ComboBox_GetTextLength(hwndCtl)
Definition: windowsx.h:59
#define CB_GETLBTEXTLEN
Definition: winuser.h:1982
#define CB_GETLBTEXT
Definition: winuser.h:1981
#define CB_ERR
Definition: winuser.h:2471
#define CB_GETCURSEL
Definition: winuser.h:1972
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by CHSourceDlgProc(), DevInstallW(), and WelcomeDlgProc().

◆ ScanFoldersForDriver()

BOOL ScanFoldersForDriver ( IN PDEVINSTDATA  DevInstData)

Definition at line 428 of file newdev.c.

430{
431 BOOL result;
432
433 /* Search in default location */
434 result = SearchDriver(DevInstData, NULL, NULL);
435
436 if (DevInstData->CustomSearchPath)
437 {
438 /* Search only in specified paths */
439 /* We need to check all specified directories to be
440 * sure to find the best driver for the device.
441 */
443 for (Path = DevInstData->CustomSearchPath; *Path != '\0'; Path += wcslen(Path) + 1)
444 {
445 TRACE("Search driver in %s\n", debugstr_w(Path));
446 if (wcslen(Path) == 2 && Path[1] == ':')
447 {
448 if (SearchDriverRecursive(DevInstData, Path))
449 result = TRUE;
450 }
451 else
452 {
453 if (SearchDriver(DevInstData, Path, NULL))
454 result = TRUE;
455 }
456 }
457 }
458
459 return result;
460}
PRTL_UNICODE_STRING_BUFFER Path
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
GLuint64EXT * result
Definition: glext.h:11304
static BOOL SearchDriver(IN PDEVINSTDATA DevInstData, IN LPCWSTR Directory OPTIONAL, IN LPCWSTR InfFile OPTIONAL)
Definition: newdev.c:260

Referenced by DevInstallW(), and FindDriverProc().

◆ SearchDriver()

static BOOL SearchDriver ( IN PDEVINSTDATA  DevInstData,
IN LPCWSTR Directory  OPTIONAL,
IN LPCWSTR InfFile  OPTIONAL 
)
static

Definition at line 260 of file newdev.c.

264{
265 SP_DEVINSTALL_PARAMS_W DevInstallParams = {0,};
266 BOOL ret;
267
268 DevInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
269 if (!SetupDiGetDeviceInstallParamsW(DevInstData->hDevInfo, &DevInstData->devInfoData, &DevInstallParams))
270 {
271 TRACE("SetupDiGetDeviceInstallParams() failed with error 0x%x\n", GetLastError());
272 return FALSE;
273 }
274 DevInstallParams.FlagsEx |= DI_FLAGSEX_ALLOWEXCLUDEDDRVS;
275
276 if (InfFile)
277 {
278 DevInstallParams.Flags |= DI_ENUMSINGLEINF;
279 wcsncpy(DevInstallParams.DriverPath, InfFile, MAX_PATH);
280 }
281 else if (Directory)
282 {
283 DevInstallParams.Flags &= ~DI_ENUMSINGLEINF;
284 wcsncpy(DevInstallParams.DriverPath, Directory, MAX_PATH);
285 }
286 else
287 {
288 DevInstallParams.Flags &= ~DI_ENUMSINGLEINF;
289 *DevInstallParams.DriverPath = '\0';
290 }
291
293 DevInstData->hDevInfo,
294 &DevInstData->devInfoData,
295 &DevInstallParams);
296 if (!ret)
297 {
298 TRACE("SetupDiSetDeviceInstallParams() failed with error 0x%x\n", GetLastError());
299 return FALSE;
300 }
301
303 DevInstData->hDevInfo,
304 &DevInstData->devInfoData,
306 if (!ret)
307 {
308 TRACE("SetupDiBuildDriverInfoList() failed with error 0x%x\n", GetLastError());
309 return FALSE;
310 }
311
312 DevInstData->drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
314 DevInstData->hDevInfo,
315 &DevInstData->devInfoData,
317 0,
318 &DevInstData->drvInfoData);
319 if (!ret)
320 {
322 return FALSE;
323 TRACE("SetupDiEnumDriverInfo() failed with error 0x%x\n", GetLastError());
324 return FALSE;
325 }
326
327 return TRUE;
328}
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI SetupDiSetDeviceInstallParamsW(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
Definition: devinst.c:4558
BOOL WINAPI SetupDiGetDeviceInstallParamsW(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
Definition: devinst.c:4451
BOOL WINAPI SetupDiBuildDriverInfoList(IN HDEVINFO DeviceInfoSet, IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN DWORD DriverType)
Definition: driver.c:718
BOOL WINAPI SetupDiEnumDriverInfoW(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN DWORD DriverType, IN DWORD MemberIndex, OUT PSP_DRVINFO_DATA_W DriverInfoData)
Definition: driver.c:1355
wcsncpy
#define DI_ENUMSINGLEINF
Definition: setupapi.h:62
SP_DRVINFO_DATA_V2 SP_DRVINFO_DATA
Definition: setupapi.h:1055
struct _SP_DEVINSTALL_PARAMS_W SP_DEVINSTALL_PARAMS_W
#define DI_FLAGSEX_ALLOWEXCLUDEDDRVS
Definition: setupapi.h:87
base for all directory entries
Definition: entries.h:138
WCHAR DriverPath[MAX_PATH]
Definition: setupapi.h:901

Referenced by ScanFoldersForDriver(), SearchDriverRecursive(), and UpdateDriverForPlugAndPlayDevicesW().

◆ SearchDriverRecursive()

static BOOL SearchDriverRecursive ( IN PDEVINSTDATA  DevInstData,
IN LPCWSTR  Path 
)
static

Definition at line 350 of file newdev.c.

353{
355 WCHAR DirPath[MAX_PATH];
357 WCHAR FullPath[MAX_PATH];
358 WCHAR LastDirPath[MAX_PATH] = L"";
359 WCHAR PathWithPattern[MAX_PATH];
360 BOOL ok = TRUE;
361 BOOL retval = FALSE;
362 HANDLE hFindFile = INVALID_HANDLE_VALUE;
363
364 wcscpy(DirPath, Path);
365
366 if (DirPath[wcslen(DirPath) - 1] != '\\')
367 wcscat(DirPath, L"\\");
368
369 wcscpy(PathWithPattern, DirPath);
370 wcscat(PathWithPattern, L"*");
371
372 for (hFindFile = FindFirstFileW(PathWithPattern, &wfd);
373 ok && hFindFile != INVALID_HANDLE_VALUE;
374 ok = FindNextFileW(hFindFile, &wfd))
375 {
376
378 if (IsDots(FileName))
379 continue;
380
382 {
383 /* Recursive search */
384 wcscpy(FullPath, DirPath);
385 wcscat(FullPath, FileName);
386 if (SearchDriverRecursive(DevInstData, FullPath))
387 {
388 retval = TRUE;
389 /* We continue the search for a better driver */
390 }
391 }
392 else
393 {
394 LPCWSTR pszExtension = GetFileExt(FileName);
395
396 if ((_wcsicmp(pszExtension, L".inf") == 0) && (wcscmp(LastDirPath, DirPath) != 0))
397 {
398 wcscpy(LastDirPath, DirPath);
399
400 if (wcslen(DirPath) > MAX_PATH)
401 /* Path is too long to be searched */
402 continue;
403
404 if (SearchDriver(DevInstData, DirPath, NULL))
405 {
406 retval = TRUE;
407 /* We continue the search for a better driver */
408 }
409
410 }
411 }
412 }
413
414 if (hFindFile != INVALID_HANDLE_VALUE)
415 FindClose(hFindFile);
416 return retval;
417}
#define ok(value,...)
Definition: atltest.h:57
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
static BOOL IsDots(IN LPCWSTR str)
Definition: newdev.c:331
static LPCWSTR GetFileExt(IN LPWSTR FileName)
Definition: newdev.c:338
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
wcscat
wcscpy
_Field_z_ WCHAR cFileName[MAX_PATH]
Definition: minwinbase.h:291
DWORD dwFileAttributes
Definition: minwinbase.h:283

Referenced by CheckBestDriver(), ScanFoldersForDriver(), and SearchDriverRecursive().

◆ UpdateDriverForPlugAndPlayDevicesA()

BOOL WINAPI UpdateDriverForPlugAndPlayDevicesA ( IN HWND  hwndParent,
IN LPCSTR  HardwareId,
IN LPCSTR  FullInfPath,
IN DWORD  InstallFlags,
OUT PBOOL bRebootRequired  OPTIONAL 
)

Definition at line 215 of file newdev.c.

221{
222 BOOL Result;
223 LPWSTR HardwareIdW = NULL;
224 LPWSTR FullInfPathW = NULL;
225
226 int len = MultiByteToWideChar(CP_ACP, 0, HardwareId, -1, NULL, 0);
227 HardwareIdW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
228 if (!HardwareIdW)
229 {
231 return FALSE;
232 }
233 MultiByteToWideChar(CP_ACP, 0, HardwareId, -1, HardwareIdW, len);
234
235 len = MultiByteToWideChar(CP_ACP, 0, FullInfPath, -1, NULL, 0);
236 FullInfPathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
237 if (!FullInfPathW)
238 {
239 HeapFree(GetProcessHeap(), 0, HardwareIdW);
241 return FALSE;
242 }
243 MultiByteToWideChar(CP_ACP, 0, FullInfPath, -1, FullInfPathW, len);
244
247 HardwareIdW,
248 FullInfPathW,
249 InstallFlags,
250 bRebootRequired);
251
252 HeapFree(GetProcessHeap(), 0, HardwareIdW);
253 HeapFree(GetProcessHeap(), 0, FullInfPathW);
254
255 return Result;
256}
static HWND hwndParent
Definition: cryptui.c:300
#define CP_ACP
Definition: compat.h:109
#define MultiByteToWideChar
Definition: compat.h:110
GLenum GLsizei len
Definition: glext.h:6722
BOOL WINAPI UpdateDriverForPlugAndPlayDevicesW(IN HWND hwndParent, IN LPCWSTR HardwareId, IN LPCWSTR FullInfPath, IN DWORD InstallFlags, OUT PBOOL bRebootRequired OPTIONAL)
Definition: newdev.c:41
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

◆ UpdateDriverForPlugAndPlayDevicesW()

BOOL WINAPI UpdateDriverForPlugAndPlayDevicesW ( IN HWND  hwndParent,
IN LPCWSTR  HardwareId,
IN LPCWSTR  FullInfPath,
IN DWORD  InstallFlags,
OUT PBOOL bRebootRequired  OPTIONAL 
)

Definition at line 41 of file newdev.c.

47{
48 DEVINSTDATA DevInstData;
49 DWORD i;
52 LPCWSTR CurrentHardwareId; /* Pointer into Buffer */
54 BOOL FoundHardwareId, FoundAtLeastOneDevice = FALSE;
55 BOOL ret = FALSE;
56
57 DevInstData.hDevInfo = INVALID_HANDLE_VALUE;
58
59 TRACE("UpdateDriverForPlugAndPlayDevicesW(%p %s %s 0x%x %p)\n",
60 hwndParent, debugstr_w(HardwareId), debugstr_w(FullInfPath), InstallFlags, bRebootRequired);
61
62 /* FIXME: InstallFlags bRebootRequired ignored! */
63
64 /* Check flags */
66 {
67 TRACE("Unknown flags: 0x%08lx\n", InstallFlags & ~(INSTALLFLAG_FORCE | INSTALLFLAG_READONLY | INSTALLFLAG_NONINTERACTIVE));
69 goto cleanup;
70 }
71
72 /* Enumerate all devices of the system */
74 if (DevInstData.hDevInfo == INVALID_HANDLE_VALUE)
75 goto cleanup;
76 DevInstData.devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
77 for (i = 0; ; i++)
78 {
79 if (!SetupDiEnumDeviceInfo(DevInstData.hDevInfo, i, &DevInstData.devInfoData))
80 {
82 {
83 TRACE("SetupDiEnumDeviceInfo() failed with error 0x%x\n", GetLastError());
84 goto cleanup;
85 }
86 /* This error was expected */
87 break;
88 }
89
90 /* Match Hardware ID */
91 FoundHardwareId = FALSE;
93 while (TRUE)
94 {
95 /* Get IDs data */
96 Buffer = NULL;
97 BufferSize = 0;
99 &DevInstData.devInfoData,
100 Property,
101 NULL,
102 (PBYTE)Buffer,
104 &BufferSize))
105 {
107 {
108 break;
109 }
111 {
112 TRACE("SetupDiGetDeviceRegistryPropertyW() failed with error 0x%x\n", GetLastError());
113 goto cleanup;
114 }
115 /* This error was expected */
118 if (!Buffer)
119 {
120 TRACE("HeapAlloc() failed\n", GetLastError());
122 goto cleanup;
123 }
124 }
125 if (Buffer)
126 {
127 /* Check if we match the given hardware ID */
128 for (CurrentHardwareId = Buffer; *CurrentHardwareId != UNICODE_NULL; CurrentHardwareId += wcslen(CurrentHardwareId) + 1)
129 {
130 if (_wcsicmp(CurrentHardwareId, HardwareId) == 0)
131 {
132 FoundHardwareId = TRUE;
133 break;
134 }
135 }
136 }
137 if (FoundHardwareId || Property == SPDRP_COMPATIBLEIDS)
138 {
139 break;
140 }
142 }
143 if (!FoundHardwareId)
144 continue;
145
146 /* We need to try to update the driver of this device */
147
148 /* Get Instance ID */
150 Buffer = NULL;
151 if (SetupDiGetDeviceInstanceIdW(DevInstData.hDevInfo, &DevInstData.devInfoData, NULL, 0, &BufferSize))
152 {
153 /* Error, as the output buffer should be too small */
155 goto cleanup;
156 }
158 {
159 TRACE("SetupDiGetDeviceInstanceIdW() failed with error 0x%x\n", GetLastError());
160 goto cleanup;
161 }
162 else if ((Buffer = HeapAlloc(GetProcessHeap(), 0, BufferSize * sizeof(WCHAR))) == NULL)
163 {
164 TRACE("HeapAlloc() failed\n", GetLastError());
166 goto cleanup;
167 }
168 else if (!SetupDiGetDeviceInstanceIdW(DevInstData.hDevInfo, &DevInstData.devInfoData, Buffer, BufferSize, NULL))
169 {
170 TRACE("SetupDiGetDeviceInstanceIdW() failed with error 0x%x\n", GetLastError());
171 goto cleanup;
172 }
173 TRACE("Trying to update the driver of %s\n", debugstr_w(Buffer));
174
175 /* Search driver in the specified .inf file */
176 if (!SearchDriver(&DevInstData, NULL, FullInfPath))
177 {
178 TRACE("SearchDriver() failed with error 0x%x\n", GetLastError());
179 continue;
180 }
181
182 /* FIXME: HACK! We shouldn't check of ERROR_PRIVILEGE_NOT_HELD */
183 //if (!InstallCurrentDriver(&DevInstData))
185 {
186 TRACE("InstallCurrentDriver() failed with error 0x%x\n", GetLastError());
187 continue;
188 }
189
190 FoundAtLeastOneDevice = TRUE;
191 }
192
193 if (FoundAtLeastOneDevice)
194 {
196 ret = TRUE;
197 }
198 else
199 {
200 TRACE("No device found with HardwareID %s\n", debugstr_w(HardwareId));
202 }
203
204cleanup:
205 if (DevInstData.hDevInfo != INVALID_HANDLE_VALUE)
208 return ret;
209}
#define NO_ERROR
Definition: dderror.h:5
#define BufferSize
Definition: mmc.h:75
BOOL WINAPI SetupDiEnumDeviceInfo(HDEVINFO devinfo, DWORD index, PSP_DEVINFO_DATA info)
Definition: devinst.c:1787
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2292
BOOL WINAPI SetupDiGetDeviceInstanceIdW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PWSTR DeviceInstanceId, DWORD DeviceInstanceIdSize, PDWORD RequiredSize)
Definition: devinst.c:1907
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define INSTALLFLAG_NONINTERACTIVE
Definition: newdev.h:36
#define INSTALLFLAG_FORCE
Definition: newdev.h:34
#define INSTALLFLAG_READONLY
Definition: newdev.h:35
#define UNICODE_NULL
BYTE * PBYTE
Definition: pedump.c:66
#define ERROR_NO_SUCH_DEVINST
Definition: setupapi.h:308
#define SPDRP_COMPATIBLEIDS
Definition: setupapi.h:510
#define DIGCF_ALLCLASSES
Definition: setupapi.h:173
#define DIGCF_PRESENT
Definition: setupapi.h:172
#define SPDRP_HARDWAREID
Definition: setupapi.h:509
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
#define ERROR_INVALID_FLAGS
Definition: winerror.h:907
#define ERROR_PRIVILEGE_NOT_HELD
Definition: winerror.h:1141

Referenced by UpdateDriverForPlugAndPlayDevicesA().

Variable Documentation

◆ hDllInstance

HINSTANCE hDllInstance

Definition at line 29 of file newdev.c.

Referenced by DllMain().