ReactOS 0.4.16-dev-1019-g2c2cdfd
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:585

Referenced by BrowseCallbackProc().

◆ ClientSideInstallW()

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

Definition at line 956 of file newdev.c.

961{
963 BOOL ShowWizard;
965 DWORD Value;
968 PWSTR InstallEventName = NULL;
970
971 /* Open the pipe */
972 hPipe = CreateFileW(lpNamedPipeName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
973
974 if(hPipe == INVALID_HANDLE_VALUE)
975 {
976 ERR("CreateFileW failed with error %u\n", GetLastError());
977 goto cleanup;
978 }
979
980 /* Read the data. Some is just included for compatibility with Windows right now and not yet used by ReactOS.
981 See umpnpmgr for more details. */
982 if(!ReadFile(hPipe, &Value, sizeof(Value), &BytesRead, NULL))
983 {
984 ERR("ReadFile failed with error %u\n", GetLastError());
985 goto cleanup;
986 }
987
988 InstallEventName = (PWSTR)HeapAlloc(GetProcessHeap(), 0, Value);
989
990 if(!ReadFile(hPipe, InstallEventName, Value, &BytesRead, NULL))
991 {
992 ERR("ReadFile failed with error %u\n", GetLastError());
993 goto cleanup;
994 }
995
996 /* I couldn't figure out what the following value means under Windows XP.
997 Therefore I used it in umpnpmgr to pass the ShowWizard variable. */
998 if(!ReadFile(hPipe, &ShowWizard, sizeof(ShowWizard), &BytesRead, NULL))
999 {
1000 ERR("ReadFile failed with error %u\n", GetLastError());
1001 goto cleanup;
1002 }
1003
1004 /* Next one is again size in bytes of the following string */
1005 if(!ReadFile(hPipe, &Value, sizeof(Value), &BytesRead, NULL))
1006 {
1007 ERR("ReadFile failed with error %u\n", GetLastError());
1008 goto cleanup;
1009 }
1010
1012
1013 if(!ReadFile(hPipe, DeviceInstance, Value, &BytesRead, NULL))
1014 {
1015 ERR("ReadFile failed with error %u\n", GetLastError());
1016 goto cleanup;
1017 }
1018
1020 if(!ReturnValue)
1021 {
1022 ERR("DevInstallW failed with error %lu\n", GetLastError());
1023 goto cleanup;
1024 }
1025
1026 hInstallEvent = CreateEventW(NULL, TRUE, FALSE, InstallEventName);
1027 if(!hInstallEvent)
1028 {
1029 TRACE("CreateEventW('%ls') failed with error %lu\n", InstallEventName, GetLastError());
1030 goto cleanup;
1031 }
1032
1035
1036cleanup:
1037 if(hPipe != INVALID_HANDLE_VALUE)
1038 CloseHandle(hPipe);
1039
1040 if(InstallEventName)
1041 HeapFree(GetProcessHeap(), 0, InstallEventName);
1042
1043 if(DeviceInstance)
1045
1046 return ReturnValue;
1047}
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:653
#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 653 of file newdev.c.

658{
659 PDEVINSTDATA DevInstData = NULL;
660 BOOL ret;
661 DWORD config_flags;
662 BOOL retval = FALSE;
663
664 TRACE("(%p, %p, %s, %d)\n", hWndParent, hInstance, debugstr_w(InstanceId), Show);
665
666 if (!IsUserAdmin())
667 {
668 /* XP kills the process... */
670 }
671
672 DevInstData = HeapAlloc(GetProcessHeap(), 0, sizeof(DEVINSTDATA));
673 if (!DevInstData)
674 {
675 TRACE("HeapAlloc() failed\n");
677 goto cleanup;
678 }
679
680 /* Clear devinst data */
681 ZeroMemory(DevInstData, sizeof(DEVINSTDATA));
682 DevInstData->devInfoData.cbSize = 0; /* Tell if the devInfoData is valid */
683
684 /* Fill devinst data */
686 if (DevInstData->hDevInfo == INVALID_HANDLE_VALUE)
687 {
688 TRACE("SetupDiCreateDeviceInfoListExW() failed with error 0x%x\n", GetLastError());
689 goto cleanup;
690 }
691
692 DevInstData->devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
694 DevInstData->hDevInfo,
696 NULL,
697 0, /* Open flags */
698 &DevInstData->devInfoData);
699 if (!ret)
700 {
701 TRACE("SetupDiOpenDeviceInfoW() failed with error 0x%x (InstanceId %s)\n",
703 DevInstData->devInfoData.cbSize = 0;
704 goto cleanup;
705 }
706
709 DevInstData->hDevInfo,
710 &DevInstData->devInfoData,
712 &DevInstData->regDataType,
713 NULL, 0,
714 &DevInstData->requiredSize);
715
716 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER && DevInstData->regDataType == REG_SZ)
717 {
718 DevInstData->buffer = HeapAlloc(GetProcessHeap(), 0, DevInstData->requiredSize);
719 if (!DevInstData->buffer)
720 {
721 TRACE("HeapAlloc() failed\n");
723 }
724 else
725 {
727 DevInstData->hDevInfo,
728 &DevInstData->devInfoData,
730 &DevInstData->regDataType,
731 DevInstData->buffer, DevInstData->requiredSize,
732 &DevInstData->requiredSize);
733 }
734 }
735 if (!ret)
736 {
737 TRACE("SetupDiGetDeviceRegistryProperty() failed with error 0x%x (InstanceId %s)\n",
739 goto cleanup;
740 }
741
743 DevInstData->hDevInfo,
744 &DevInstData->devInfoData,
746 NULL,
747 (BYTE *)&config_flags,
748 sizeof(config_flags),
749 NULL))
750 {
751 if (config_flags & CONFIGFLAG_FAILEDINSTALL)
752 {
753 /* The device is disabled */
754 TRACE("Device is disabled\n");
755 retval = TRUE;
756 goto cleanup;
757 }
758 }
759
760 TRACE("Installing %s (%s)\n", debugstr_w((PCWSTR)DevInstData->buffer), debugstr_w(InstanceId));
761
762 /* Search driver in default location and removable devices */
763 if (!PrepareFoldersToScan(DevInstData, FALSE, FALSE, NULL))
764 {
765 TRACE("PrepareFoldersToScan() failed with error 0x%lx\n", GetLastError());
766 goto cleanup;
767 }
768 if (ScanFoldersForDriver(DevInstData))
769 {
770 /* Driver found ; install it */
771 retval = InstallCurrentDriver(DevInstData);
772 TRACE("InstallCurrentDriver() returned %d\n", retval);
773 if (retval && Show != SW_HIDE)
774 {
775 /* Should we display the 'Need to reboot' page? */
776 SP_DEVINSTALL_PARAMS installParams;
777 installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
779 DevInstData->hDevInfo,
780 &DevInstData->devInfoData,
781 &installParams))
782 {
783 if (installParams.Flags & (DI_NEEDRESTART | DI_NEEDREBOOT))
784 {
785 TRACE("Displaying 'Reboot' wizard page\n");
787 }
788 }
789 }
790 goto cleanup;
791 }
792 else if (Show == SW_HIDE)
793 {
794 /* We can't show the wizard. Fail the install */
795 TRACE("No wizard\n");
796 goto cleanup;
797 }
798
799 /* Prepare the wizard, and display it */
800 TRACE("Need to show install wizard\n");
802
803cleanup:
804 if (DevInstData)
805 {
806 if (DevInstData->devInfoData.cbSize != 0)
807 {
808 if (!SetupDiDestroyDriverInfoList(DevInstData->hDevInfo, &DevInstData->devInfoData, SPDIT_COMPATDRIVER))
809 TRACE("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
810 }
811 if (DevInstData->hDevInfo != INVALID_HANDLE_VALUE)
812 {
813 if (!SetupDiDestroyDeviceInfoList(DevInstData->hDevInfo))
814 TRACE("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
815 }
816 HeapFree(GetProcessHeap(), 0, DevInstData->buffer);
817 HeapFree(GetProcessHeap(), 0, DevInstData);
818 }
819
820 return retval;
821}
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:1487
#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
_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
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:537
BOOL DisplayWizard(IN PDEVINSTDATA DevInstData, IN HWND hwndParent, IN UINT startPage)
Definition: wizard.c:1378
#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 ret
int retval
Definition: wcstombs.cpp:91
#define ZeroMemory
Definition: winbase.h:1743
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
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 1050 of file newdev.c.

1054{
1056 {
1058
1060
1061 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
1065 }
1066
1067 return TRUE;
1068}
DWORD dwReason
Definition: misc.cpp:135
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:900
#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 Dot(u, v)
Definition: normal.c:49
#define L(x)
Definition: ntvdm.h:50
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by SearchDriverRecursive().

◆ InstallCurrentDriver()

BOOL InstallCurrentDriver ( IN PDEVINSTDATA  DevInstData)

Definition at line 537 of file newdev.c.

539{
540 BOOL ret;
541
542 TRACE("Installing driver %s: %s\n",
543 debugstr_w(DevInstData->drvInfoData.MfgName),
544 debugstr_w(DevInstData->drvInfoData.Description));
545
548 DevInstData->hDevInfo,
549 &DevInstData->devInfoData);
550 if (!ret)
551 {
552 TRACE("SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV) failed with error 0x%x\n", GetLastError());
553 return FALSE;
554 }
555
558 DevInstData->hDevInfo,
559 &DevInstData->devInfoData);
560 if (!ret)
561 {
562 TRACE("SetupDiCallClassInstaller(DIF_ALLOW_INSTALL) failed with error 0x%x\n", GetLastError());
563 return FALSE;
564 }
565
568 DevInstData->hDevInfo,
569 &DevInstData->devInfoData);
570 if (!ret)
571 {
572 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_PREANALYZE) failed with error 0x%x\n", GetLastError());
573 return FALSE;
574 }
575
578 DevInstData->hDevInfo,
579 &DevInstData->devInfoData);
580 if (!ret)
581 {
582 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_POSTANALYZE) failed with error 0x%x\n", GetLastError());
583 return FALSE;
584 }
585
588 DevInstData->hDevInfo,
589 &DevInstData->devInfoData);
590 if (!ret)
591 {
592 TRACE("SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES) failed with error 0x%x\n", GetLastError());
593 return FALSE;
594 }
595
598 DevInstData->hDevInfo,
599 &DevInstData->devInfoData);
600 if (!ret)
601 {
602 TRACE("SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS) failed with error 0x%x\n", GetLastError());
603 return FALSE;
604 }
605
608 DevInstData->hDevInfo,
609 &DevInstData->devInfoData);
610 if (!ret)
611 {
612 TRACE("SetupDiCallClassInstaller(DIF_INSTALLINTERFACES) failed with error 0x%x\n", GetLastError());
613 return FALSE;
614 }
615
618 DevInstData->hDevInfo,
619 &DevInstData->devInfoData);
620 if (!ret)
621 {
622 TRACE("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed with error 0x%x\n", GetLastError());
623 return FALSE;
624 }
625
628 DevInstData->hDevInfo,
629 &DevInstData->devInfoData);
630 if (!ret)
631 {
632 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_FINISHINSTALL) failed with error 0x%x\n", GetLastError());
633 return FALSE;
634 }
635
638 DevInstData->hDevInfo,
639 &DevInstData->devInfoData);
640 if (!ret)
641 {
642 TRACE("SetupDiCallClassInstaller(DIF_DESTROYPRIVATEDATA) failed with error 0x%x\n", GetLastError());
643 return FALSE;
644 }
645
646 return TRUE;
647}
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 942 of file newdev.c.

947{
948 return InstallDevInstEx(hWndParent, InstanceId, bUpdate, lpReboot, 0);
949}
BOOL WINAPI InstallDevInstEx(IN HWND hWndParent, IN LPCWSTR InstanceId, IN BOOL bUpdate, OUT LPDWORD lpReboot, IN DWORD Unknown)
Definition: newdev.c:826

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 826 of file newdev.c.

832{
833 PDEVINSTDATA DevInstData = NULL;
834 BOOL ret;
835 BOOL retval = FALSE;
836
837 TRACE("InstllDevInstEx(%p, %s, %d, %p, %lx)\n",
838 hWndParent, debugstr_w(InstanceId), bUpdate, lpReboot, Unknown);
839
840 DevInstData = HeapAlloc(GetProcessHeap(), 0, sizeof(DEVINSTDATA));
841 if (!DevInstData)
842 {
843 TRACE("HeapAlloc() failed\n");
845 goto cleanup;
846 }
847
848 /* Clear devinst data */
849 ZeroMemory(DevInstData, sizeof(DEVINSTDATA));
850 DevInstData->devInfoData.cbSize = 0; /* Tell if the devInfoData is valid */
851 DevInstData->bUpdate = bUpdate;
852
853 /* Fill devinst data */
855 if (DevInstData->hDevInfo == INVALID_HANDLE_VALUE)
856 {
857 TRACE("SetupDiCreateDeviceInfoListExW() failed with error 0x%x\n", GetLastError());
858 goto cleanup;
859 }
860
861 DevInstData->devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
863 DevInstData->hDevInfo,
865 NULL,
866 0, /* Open flags */
867 &DevInstData->devInfoData);
868 if (!ret)
869 {
870 TRACE("SetupDiOpenDeviceInfoW() failed with error 0x%x (InstanceId %s)\n",
872 DevInstData->devInfoData.cbSize = 0;
873 goto cleanup;
874 }
875
878 DevInstData->hDevInfo,
879 &DevInstData->devInfoData,
881 &DevInstData->regDataType,
882 NULL, 0,
883 &DevInstData->requiredSize);
884
885 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER && DevInstData->regDataType == REG_SZ)
886 {
887 DevInstData->buffer = HeapAlloc(GetProcessHeap(), 0, DevInstData->requiredSize);
888 if (!DevInstData->buffer)
889 {
890 TRACE("HeapAlloc() failed\n");
892 }
893 else
894 {
896 DevInstData->hDevInfo,
897 &DevInstData->devInfoData,
899 &DevInstData->regDataType,
900 DevInstData->buffer, DevInstData->requiredSize,
901 &DevInstData->requiredSize);
902 }
903 }
904
905 if (!ret)
906 {
907 TRACE("SetupDiGetDeviceRegistryProperty() failed with error 0x%x (InstanceId %s)\n",
909 goto cleanup;
910 }
911
912 /* Prepare the wizard, and display it */
913 TRACE("Need to show install wizard\n");
915
916cleanup:
917 if (DevInstData)
918 {
919 if (DevInstData->devInfoData.cbSize != 0)
920 {
921 if (!SetupDiDestroyDriverInfoList(DevInstData->hDevInfo, &DevInstData->devInfoData, SPDIT_COMPATDRIVER))
922 TRACE("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
923 }
924 if (DevInstData->hDevInfo != INVALID_HANDLE_VALUE)
925 {
926 if (!SetupDiDestroyDeviceInfoList(DevInstData->hDevInfo))
927 TRACE("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
928 }
929 HeapFree(GetProcessHeap(), 0, DevInstData->buffer);
930 HeapFree(GetProcessHeap(), 0, DevInstData);
931 }
932
933 return retval;
934}
@ 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}
const WCHAR * str
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

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
477 /* Calculate length needed to store the search paths */
478 if (IncludeRemovableDevices)
479 {
480 dwDrives = GetLogicalDrives();
481 for (drive[0] = 'A', i = 1; drive[0] <= 'Z'; drive[0]++, i <<= 1)
482 {
483 if (dwDrives & i)
484 {
485 nType = GetDriveTypeW(drive);
486 if (nType == DRIVE_REMOVABLE || nType == DRIVE_CDROM)
487 {
488 LengthNeeded += 3;
489 }
490 }
491 }
492 }
493 if (IncludeCustomPath)
494 {
495 CustomTextLength = 1 + ComboBox_GetTextLength(hwndCombo);
496 LengthNeeded += CustomTextLength;
497 }
498
499 /* Allocate space for search paths */
500 HeapFree(GetProcessHeap(), 0, DevInstData->CustomSearchPath);
501 DevInstData->CustomSearchPath = Buffer = HeapAlloc(
503 0,
504 (LengthNeeded + 1) * sizeof(WCHAR));
505 if (!Buffer)
506 {
507 TRACE("HeapAlloc() failed\n");
509 return FALSE;
510 }
511
512 /* Fill search paths */
513 if (IncludeRemovableDevices)
514 {
515 for (drive[0] = 'A', i = 1; drive[0] <= 'Z'; drive[0]++, i <<= 1)
516 {
517 if (dwDrives & i)
518 {
519 nType = GetDriveTypeW(drive);
520 if (nType == DRIVE_REMOVABLE || nType == DRIVE_CDROM)
521 {
522 Buffer += 1 + swprintf(Buffer, drive);
523 }
524 }
525 }
526 }
527 if (IncludeCustomPath)
528 {
529 Buffer += 1 + GetWindowTextW(hwndCombo, Buffer, CustomTextLength);
530 }
531 *Buffer = '\0';
532
533 return TRUE;
534}
Definition: bufpool.h:45
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
#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
unsigned int UINT
Definition: ndis.h:50
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1394
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
#define DRIVE_REMOVABLE
Definition: winbase.h:277
#define ComboBox_GetTextLength(hwndCtl)
Definition: windowsx.h:59
__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
GLuint64EXT * result
Definition: glext.h:11304
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
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}
wcsncpy
#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
#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
377 wcscpy(FileName, wfd.cFileName);
378 if (IsDots(FileName))
379 continue;
380
381 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
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
wcscat
wcscpy
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
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
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

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:583
#define ERROR_PRIVILEGE_NOT_HELD
Definition: winerror.h:796

Referenced by UpdateDriverForPlugAndPlayDevicesA().

Variable Documentation

◆ hDllInstance

HINSTANCE hDllInstance

Definition at line 29 of file newdev.c.

Referenced by DllMain().