ReactOS 0.4.15-dev-7958-gcd0bb1a
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 412 of file newdev.c.

415{
416 return SearchDriverRecursive(DevInstData, pszDir);
417}
static BOOL SearchDriverRecursive(IN PDEVINSTDATA DevInstData, IN LPCWSTR Path)
Definition: newdev.c:342
_In_ LPCSTR pszDir
Definition: shellapi.h:584

Referenced by BrowseCallbackProc().

◆ ClientSideInstallW()

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

Definition at line 948 of file newdev.c.

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

◆ DevInstallW()

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

Definition at line 645 of file newdev.c.

650{
651 PDEVINSTDATA DevInstData = NULL;
652 BOOL ret;
653 DWORD config_flags;
654 BOOL retval = FALSE;
655
656 TRACE("(%p, %p, %s, %d)\n", hWndParent, hInstance, debugstr_w(InstanceId), Show);
657
658 if (!IsUserAdmin())
659 {
660 /* XP kills the process... */
662 }
663
664 DevInstData = HeapAlloc(GetProcessHeap(), 0, sizeof(DEVINSTDATA));
665 if (!DevInstData)
666 {
667 TRACE("HeapAlloc() failed\n");
669 goto cleanup;
670 }
671
672 /* Clear devinst data */
673 ZeroMemory(DevInstData, sizeof(DEVINSTDATA));
674 DevInstData->devInfoData.cbSize = 0; /* Tell if the devInfoData is valid */
675
676 /* Fill devinst data */
678 if (DevInstData->hDevInfo == INVALID_HANDLE_VALUE)
679 {
680 TRACE("SetupDiCreateDeviceInfoListExW() failed with error 0x%x\n", GetLastError());
681 goto cleanup;
682 }
683
684 DevInstData->devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
686 DevInstData->hDevInfo,
688 NULL,
689 0, /* Open flags */
690 &DevInstData->devInfoData);
691 if (!ret)
692 {
693 TRACE("SetupDiOpenDeviceInfoW() failed with error 0x%x (InstanceId %s)\n",
695 DevInstData->devInfoData.cbSize = 0;
696 goto cleanup;
697 }
698
701 DevInstData->hDevInfo,
702 &DevInstData->devInfoData,
704 &DevInstData->regDataType,
705 NULL, 0,
706 &DevInstData->requiredSize);
707
708 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER && DevInstData->regDataType == REG_SZ)
709 {
710 DevInstData->buffer = HeapAlloc(GetProcessHeap(), 0, DevInstData->requiredSize);
711 if (!DevInstData->buffer)
712 {
713 TRACE("HeapAlloc() failed\n");
715 }
716 else
717 {
719 DevInstData->hDevInfo,
720 &DevInstData->devInfoData,
722 &DevInstData->regDataType,
723 DevInstData->buffer, DevInstData->requiredSize,
724 &DevInstData->requiredSize);
725 }
726 }
727 if (!ret)
728 {
729 TRACE("SetupDiGetDeviceRegistryProperty() failed with error 0x%x (InstanceId %s)\n",
731 goto cleanup;
732 }
733
735 DevInstData->hDevInfo,
736 &DevInstData->devInfoData,
738 NULL,
739 (BYTE *)&config_flags,
740 sizeof(config_flags),
741 NULL))
742 {
743 if (config_flags & CONFIGFLAG_FAILEDINSTALL)
744 {
745 /* The device is disabled */
746 TRACE("Device is disabled\n");
747 retval = TRUE;
748 goto cleanup;
749 }
750 }
751
752 TRACE("Installing %s (%s)\n", debugstr_w((PCWSTR)DevInstData->buffer), debugstr_w(InstanceId));
753
754 /* Search driver in default location and removable devices */
755 if (!PrepareFoldersToScan(DevInstData, FALSE, FALSE, NULL))
756 {
757 TRACE("PrepareFoldersToScan() failed with error 0x%lx\n", GetLastError());
758 goto cleanup;
759 }
760 if (ScanFoldersForDriver(DevInstData))
761 {
762 /* Driver found ; install it */
763 retval = InstallCurrentDriver(DevInstData);
764 TRACE("InstallCurrentDriver() returned %d\n", retval);
765 if (retval && Show != SW_HIDE)
766 {
767 /* Should we display the 'Need to reboot' page? */
768 SP_DEVINSTALL_PARAMS installParams;
769 installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
771 DevInstData->hDevInfo,
772 &DevInstData->devInfoData,
773 &installParams))
774 {
775 if (installParams.Flags & (DI_NEEDRESTART | DI_NEEDREBOOT))
776 {
777 TRACE("Displaying 'Reboot' wizard page\n");
778 retval = DisplayWizard(DevInstData, hWndParent, IDD_NEEDREBOOT);
779 }
780 }
781 }
782 goto cleanup;
783 }
784 else if (Show == SW_HIDE)
785 {
786 /* We can't show the wizard. Fail the install */
787 TRACE("No wizard\n");
788 goto cleanup;
789 }
790
791 /* Prepare the wizard, and display it */
792 TRACE("Need to show install wizard\n");
793 retval = DisplayWizard(DevInstData, hWndParent, IDD_WELCOMEPAGE);
794
795cleanup:
796 if (DevInstData)
797 {
798 if (DevInstData->devInfoData.cbSize != 0)
799 {
800 if (!SetupDiDestroyDriverInfoList(DevInstData->hDevInfo, &DevInstData->devInfoData, SPDIT_COMPATDRIVER))
801 TRACE("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
802 }
803 if (DevInstData->hDevInfo != INVALID_HANDLE_VALUE)
804 {
805 if (!SetupDiDestroyDeviceInfoList(DevInstData->hDevInfo))
806 TRACE("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
807 }
808 HeapFree(GetProcessHeap(), 0, DevInstData->buffer);
809 HeapFree(GetProcessHeap(), 0, DevInstData);
810 }
811
812 return retval;
813}
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:420
BOOL PrepareFoldersToScan(IN PDEVINSTDATA DevInstData, IN BOOL IncludeRemovableDevices, IN BOOL IncludeCustomPath, IN HWND hwndCombo OPTIONAL)
Definition: newdev.c:455
BOOL InstallCurrentDriver(IN PDEVINSTDATA DevInstData)
Definition: newdev.c:529
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:507
#define SetupDiGetDeviceInstallParams
Definition: setupapi.h:2599
SP_DEVINSTALL_PARAMS_A SP_DEVINSTALL_PARAMS
Definition: setupapi.h:1155
#define SetupDiGetDeviceRegistryProperty
Definition: setupapi.h:2603
#define DI_NEEDREBOOT
Definition: setupapi.h:54
struct _SP_DEVINFO_DATA SP_DEVINFO_DATA
#define SPDRP_CONFIGFLAGS
Definition: setupapi.h:517
#define SPDIT_COMPATDRIVER
Definition: setupapi.h:506
SP_DEVINFO_DATA devInfoData
HDEVINFO hDevInfo
DWORD requiredSize
const uint16_t * PCWSTR
Definition: typedefs.h:57
int ret
#define ZeroMemory
Definition: winbase.h:1712
#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 1042 of file newdev.c.

1046{
1048 {
1050
1052
1053 InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
1057 }
1058
1059 return TRUE;
1060}
DWORD dwReason
Definition: misc.cpp:154
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#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 330 of file newdev.c.

331{
332 LPCWSTR Dot;
333
334 Dot = wcsrchr(FileName, '.');
335 if (!Dot)
336 return L"";
337
338 return Dot;
339}
#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 529 of file newdev.c.

531{
532 BOOL ret;
533
534 TRACE("Installing driver %s: %s\n",
535 debugstr_w(DevInstData->drvInfoData.MfgName),
536 debugstr_w(DevInstData->drvInfoData.Description));
537
540 DevInstData->hDevInfo,
541 &DevInstData->devInfoData);
542 if (!ret)
543 {
544 TRACE("SetupDiCallClassInstaller(DIF_SELECTBESTCOMPATDRV) failed with error 0x%x\n", GetLastError());
545 return FALSE;
546 }
547
550 DevInstData->hDevInfo,
551 &DevInstData->devInfoData);
552 if (!ret)
553 {
554 TRACE("SetupDiCallClassInstaller(DIF_ALLOW_INSTALL) failed with error 0x%x\n", GetLastError());
555 return FALSE;
556 }
557
560 DevInstData->hDevInfo,
561 &DevInstData->devInfoData);
562 if (!ret)
563 {
564 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_PREANALYZE) failed with error 0x%x\n", GetLastError());
565 return FALSE;
566 }
567
570 DevInstData->hDevInfo,
571 &DevInstData->devInfoData);
572 if (!ret)
573 {
574 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_POSTANALYZE) failed with error 0x%x\n", GetLastError());
575 return FALSE;
576 }
577
580 DevInstData->hDevInfo,
581 &DevInstData->devInfoData);
582 if (!ret)
583 {
584 TRACE("SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES) failed with error 0x%x\n", GetLastError());
585 return FALSE;
586 }
587
590 DevInstData->hDevInfo,
591 &DevInstData->devInfoData);
592 if (!ret)
593 {
594 TRACE("SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS) failed with error 0x%x\n", GetLastError());
595 return FALSE;
596 }
597
600 DevInstData->hDevInfo,
601 &DevInstData->devInfoData);
602 if (!ret)
603 {
604 TRACE("SetupDiCallClassInstaller(DIF_INSTALLINTERFACES) failed with error 0x%x\n", GetLastError());
605 return FALSE;
606 }
607
610 DevInstData->hDevInfo,
611 &DevInstData->devInfoData);
612 if (!ret)
613 {
614 TRACE("SetupDiCallClassInstaller(DIF_INSTALLDEVICE) failed with error 0x%x\n", GetLastError());
615 return FALSE;
616 }
617
620 DevInstData->hDevInfo,
621 &DevInstData->devInfoData);
622 if (!ret)
623 {
624 TRACE("SetupDiCallClassInstaller(DIF_NEWDEVICEWIZARD_FINISHINSTALL) failed with error 0x%x\n", GetLastError());
625 return FALSE;
626 }
627
630 DevInstData->hDevInfo,
631 &DevInstData->devInfoData);
632 if (!ret)
633 {
634 TRACE("SetupDiCallClassInstaller(DIF_DESTROYPRIVATEDATA) failed with error 0x%x\n", GetLastError());
635 return FALSE;
636 }
637
638 return TRUE;
639}
BOOL WINAPI SetupDiCallClassInstaller(DI_FUNCTION InstallFunction, HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:4024
#define DIF_INSTALLDEVICEFILES
Definition: setupapi.h:140
#define DIF_REGISTER_COINSTALLERS
Definition: setupapi.h:153
#define DIF_INSTALLINTERFACES
Definition: setupapi.h:151
#define DIF_NEWDEVICEWIZARD_PREANALYZE
Definition: setupapi.h:147
#define DIF_INSTALLDEVICE
Definition: setupapi.h:121
#define DIF_ALLOW_INSTALL
Definition: setupapi.h:143
#define DIF_DESTROYPRIVATEDATA
Definition: setupapi.h:131
#define DIF_SELECTBESTCOMPATDRV
Definition: setupapi.h:142
#define DIF_NEWDEVICEWIZARD_POSTANALYZE
Definition: setupapi.h:148
#define DIF_NEWDEVICEWIZARD_FINISHINSTALL
Definition: setupapi.h:149

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

939{
940 return InstallDevInstEx(hWndParent, InstanceId, bUpdate, lpReboot, 0);
941}
BOOL WINAPI InstallDevInstEx(IN HWND hWndParent, IN LPCWSTR InstanceId, IN BOOL bUpdate, OUT LPDWORD lpReboot, IN DWORD Unknown)
Definition: newdev.c:818

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

824{
825 PDEVINSTDATA DevInstData = NULL;
826 BOOL ret;
827 BOOL retval = FALSE;
828
829 TRACE("InstllDevInstEx(%p, %s, %d, %p, %lx)\n",
830 hWndParent, debugstr_w(InstanceId), bUpdate, lpReboot, Unknown);
831
832 DevInstData = HeapAlloc(GetProcessHeap(), 0, sizeof(DEVINSTDATA));
833 if (!DevInstData)
834 {
835 TRACE("HeapAlloc() failed\n");
837 goto cleanup;
838 }
839
840 /* Clear devinst data */
841 ZeroMemory(DevInstData, sizeof(DEVINSTDATA));
842 DevInstData->devInfoData.cbSize = 0; /* Tell if the devInfoData is valid */
843 DevInstData->bUpdate = bUpdate;
844
845 /* Fill devinst data */
847 if (DevInstData->hDevInfo == INVALID_HANDLE_VALUE)
848 {
849 TRACE("SetupDiCreateDeviceInfoListExW() failed with error 0x%x\n", GetLastError());
850 goto cleanup;
851 }
852
853 DevInstData->devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
855 DevInstData->hDevInfo,
857 NULL,
858 0, /* Open flags */
859 &DevInstData->devInfoData);
860 if (!ret)
861 {
862 TRACE("SetupDiOpenDeviceInfoW() failed with error 0x%x (InstanceId %s)\n",
864 DevInstData->devInfoData.cbSize = 0;
865 goto cleanup;
866 }
867
870 DevInstData->hDevInfo,
871 &DevInstData->devInfoData,
873 &DevInstData->regDataType,
874 NULL, 0,
875 &DevInstData->requiredSize);
876
877 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER && DevInstData->regDataType == REG_SZ)
878 {
879 DevInstData->buffer = HeapAlloc(GetProcessHeap(), 0, DevInstData->requiredSize);
880 if (!DevInstData->buffer)
881 {
882 TRACE("HeapAlloc() failed\n");
884 }
885 else
886 {
888 DevInstData->hDevInfo,
889 &DevInstData->devInfoData,
891 &DevInstData->regDataType,
892 DevInstData->buffer, DevInstData->requiredSize,
893 &DevInstData->requiredSize);
894 }
895 }
896
897 if (!ret)
898 {
899 TRACE("SetupDiGetDeviceRegistryProperty() failed with error 0x%x (InstanceId %s)\n",
901 goto cleanup;
902 }
903
904 /* Prepare the wizard, and display it */
905 TRACE("Need to show install wizard\n");
906 retval = DisplayWizard(DevInstData, hWndParent, IDD_WELCOMEPAGE);
907
908cleanup:
909 if (DevInstData)
910 {
911 if (DevInstData->devInfoData.cbSize != 0)
912 {
913 if (!SetupDiDestroyDriverInfoList(DevInstData->hDevInfo, &DevInstData->devInfoData, SPDIT_COMPATDRIVER))
914 TRACE("SetupDiDestroyDriverInfoList() failed with error 0x%lx\n", GetLastError());
915 }
916 if (DevInstData->hDevInfo != INVALID_HANDLE_VALUE)
917 {
918 if (!SetupDiDestroyDeviceInfoList(DevInstData->hDevInfo))
919 TRACE("SetupDiDestroyDeviceInfoList() failed with error 0x%lx\n", GetLastError());
920 }
921 HeapFree(GetProcessHeap(), 0, DevInstData->buffer);
922 HeapFree(GetProcessHeap(), 0, DevInstData);
923 }
924
925 return retval;
926}
@ Unknown
Definition: i8042prt.h:114

Referenced by InstallDevInst().

◆ IsDots()

static BOOL IsDots ( IN LPCWSTR  str)
static

Definition at line 323 of file newdev.c.

324{
325 if(wcscmp(str, L".") && wcscmp(str, L"..")) return FALSE;
326 return TRUE;
327}
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 455 of file newdev.c.

460{
461 WCHAR drive[] = {'?',':',0};
462 DWORD dwDrives = 0;
463 DWORD i;
464 UINT nType;
465 DWORD CustomTextLength = 0;
468
469 /* Calculate length needed to store the search paths */
470 if (IncludeRemovableDevices)
471 {
472 dwDrives = GetLogicalDrives();
473 for (drive[0] = 'A', i = 1; drive[0] <= 'Z'; drive[0]++, i <<= 1)
474 {
475 if (dwDrives & i)
476 {
477 nType = GetDriveTypeW(drive);
478 if (nType == DRIVE_REMOVABLE || nType == DRIVE_CDROM)
479 {
480 LengthNeeded += 3;
481 }
482 }
483 }
484 }
485 if (IncludeCustomPath)
486 {
487 CustomTextLength = 1 + ComboBox_GetTextLength(hwndCombo);
488 LengthNeeded += CustomTextLength;
489 }
490
491 /* Allocate space for search paths */
492 HeapFree(GetProcessHeap(), 0, DevInstData->CustomSearchPath);
493 DevInstData->CustomSearchPath = Buffer = HeapAlloc(
495 0,
496 (LengthNeeded + 1) * sizeof(WCHAR));
497 if (!Buffer)
498 {
499 TRACE("HeapAlloc() failed\n");
501 return FALSE;
502 }
503
504 /* Fill search paths */
505 if (IncludeRemovableDevices)
506 {
507 for (drive[0] = 'A', i = 1; drive[0] <= 'Z'; drive[0]++, i <<= 1)
508 {
509 if (dwDrives & i)
510 {
511 nType = GetDriveTypeW(drive);
512 if (nType == DRIVE_REMOVABLE || nType == DRIVE_CDROM)
513 {
514 Buffer += 1 + swprintf(Buffer, drive);
515 }
516 }
517 }
518 }
519 if (IncludeCustomPath)
520 {
521 Buffer += 1 + GetWindowTextW(hwndCombo, Buffer, CustomTextLength);
522 }
523 *Buffer = '\0';
524
525 return TRUE;
526}
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:1412
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
#define DRIVE_REMOVABLE
Definition: winbase.h:251
#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 420 of file newdev.c.

422{
423 BOOL result;
424
425 /* Search in default location */
426 result = SearchDriver(DevInstData, NULL, NULL);
427
428 if (DevInstData->CustomSearchPath)
429 {
430 /* Search only in specified paths */
431 /* We need to check all specified directories to be
432 * sure to find the best driver for the device.
433 */
435 for (Path = DevInstData->CustomSearchPath; *Path != '\0'; Path += wcslen(Path) + 1)
436 {
437 TRACE("Search driver in %s\n", debugstr_w(Path));
438 if (wcslen(Path) == 2 && Path[1] == ':')
439 {
440 if (SearchDriverRecursive(DevInstData, Path))
441 result = TRUE;
442 }
443 else
444 {
445 if (SearchDriver(DevInstData, Path, NULL))
446 result = TRUE;
447 }
448 }
449 }
450
451 return result;
452}
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:252

Referenced by DevInstallW(), and FindDriverProc().

◆ SearchDriver()

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

Definition at line 252 of file newdev.c.

256{
257 SP_DEVINSTALL_PARAMS_W DevInstallParams = {0,};
258 BOOL ret;
259
260 DevInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
261 if (!SetupDiGetDeviceInstallParamsW(DevInstData->hDevInfo, &DevInstData->devInfoData, &DevInstallParams))
262 {
263 TRACE("SetupDiGetDeviceInstallParams() failed with error 0x%x\n", GetLastError());
264 return FALSE;
265 }
266 DevInstallParams.FlagsEx |= DI_FLAGSEX_ALLOWEXCLUDEDDRVS;
267
268 if (InfFile)
269 {
270 DevInstallParams.Flags |= DI_ENUMSINGLEINF;
271 wcsncpy(DevInstallParams.DriverPath, InfFile, MAX_PATH);
272 }
273 else if (Directory)
274 {
275 DevInstallParams.Flags &= ~DI_ENUMSINGLEINF;
276 wcsncpy(DevInstallParams.DriverPath, Directory, MAX_PATH);
277 }
278 else
279 {
280 DevInstallParams.Flags &= ~DI_ENUMSINGLEINF;
281 *DevInstallParams.DriverPath = '\0';
282 }
283
285 DevInstData->hDevInfo,
286 &DevInstData->devInfoData,
287 &DevInstallParams);
288 if (!ret)
289 {
290 TRACE("SetupDiSetDeviceInstallParams() failed with error 0x%x\n", GetLastError());
291 return FALSE;
292 }
293
295 DevInstData->hDevInfo,
296 &DevInstData->devInfoData,
298 if (!ret)
299 {
300 TRACE("SetupDiBuildDriverInfoList() failed with error 0x%x\n", GetLastError());
301 return FALSE;
302 }
303
304 DevInstData->drvInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
306 DevInstData->hDevInfo,
307 &DevInstData->devInfoData,
309 0,
310 &DevInstData->drvInfoData);
311 if (!ret)
312 {
314 return FALSE;
315 TRACE("SetupDiEnumDriverInfo() failed with error 0x%x\n", GetLastError());
316 return FALSE;
317 }
318
319 return TRUE;
320}
#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
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define DI_ENUMSINGLEINF
Definition: setupapi.h:62
SP_DRVINFO_DATA_V2 SP_DRVINFO_DATA
Definition: setupapi.h:1054
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:900

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

◆ SearchDriverRecursive()

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

Definition at line 342 of file newdev.c.

345{
347 WCHAR DirPath[MAX_PATH];
349 WCHAR FullPath[MAX_PATH];
350 WCHAR LastDirPath[MAX_PATH] = L"";
351 WCHAR PathWithPattern[MAX_PATH];
352 BOOL ok = TRUE;
353 BOOL retval = FALSE;
354 HANDLE hFindFile = INVALID_HANDLE_VALUE;
355
356 wcscpy(DirPath, Path);
357
358 if (DirPath[wcslen(DirPath) - 1] != '\\')
359 wcscat(DirPath, L"\\");
360
361 wcscpy(PathWithPattern, DirPath);
362 wcscat(PathWithPattern, L"*");
363
364 for (hFindFile = FindFirstFileW(PathWithPattern, &wfd);
365 ok && hFindFile != INVALID_HANDLE_VALUE;
366 ok = FindNextFileW(hFindFile, &wfd))
367 {
368
369 wcscpy(FileName, wfd.cFileName);
370 if (IsDots(FileName))
371 continue;
372
373 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
374 {
375 /* Recursive search */
376 wcscpy(FullPath, DirPath);
377 wcscat(FullPath, FileName);
378 if (SearchDriverRecursive(DevInstData, FullPath))
379 {
380 retval = TRUE;
381 /* We continue the search for a better driver */
382 }
383 }
384 else
385 {
386 LPCWSTR pszExtension = GetFileExt(FileName);
387
388 if ((_wcsicmp(pszExtension, L".inf") == 0) && (wcscmp(LastDirPath, DirPath) != 0))
389 {
390 wcscpy(LastDirPath, DirPath);
391
392 if (wcslen(DirPath) > MAX_PATH)
393 /* Path is too long to be searched */
394 continue;
395
396 if (SearchDriver(DevInstData, DirPath, NULL))
397 {
398 retval = TRUE;
399 /* We continue the search for a better driver */
400 }
401
402 }
403 }
404 }
405
406 if (hFindFile != INVALID_HANDLE_VALUE)
407 FindClose(hFindFile);
408 return retval;
409}
#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
static BOOL IsDots(IN LPCWSTR str)
Definition: newdev.c:323
static LPCWSTR GetFileExt(IN LPWSTR FileName)
Definition: newdev.c:330
#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)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

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

213{
214 BOOL Result;
215 LPWSTR HardwareIdW = NULL;
216 LPWSTR FullInfPathW = NULL;
217
218 int len = MultiByteToWideChar(CP_ACP, 0, HardwareId, -1, NULL, 0);
219 HardwareIdW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
220 if (!HardwareIdW)
221 {
223 return FALSE;
224 }
225 MultiByteToWideChar(CP_ACP, 0, HardwareId, -1, HardwareIdW, len);
226
227 len = MultiByteToWideChar(CP_ACP, 0, FullInfPath, -1, NULL, 0);
228 FullInfPathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
229 if (!FullInfPathW)
230 {
231 HeapFree(GetProcessHeap(), 0, HardwareIdW);
233 return FALSE;
234 }
235 MultiByteToWideChar(CP_ACP, 0, FullInfPath, -1, FullInfPathW, len);
236
239 HardwareIdW,
240 FullInfPathW,
241 InstallFlags,
242 bRebootRequired);
243
244 HeapFree(GetProcessHeap(), 0, HardwareIdW);
245 HeapFree(GetProcessHeap(), 0, FullInfPathW);
246
247 return Result;
248}
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 */
53 BOOL FoundHardwareId, FoundAtLeastOneDevice = FALSE;
54 BOOL ret = FALSE;
55
56 DevInstData.hDevInfo = INVALID_HANDLE_VALUE;
57
58 TRACE("UpdateDriverForPlugAndPlayDevicesW(%p %s %s 0x%x %p)\n",
59 hwndParent, debugstr_w(HardwareId), debugstr_w(FullInfPath), InstallFlags, bRebootRequired);
60
61 /* FIXME: InstallFlags bRebootRequired ignored! */
62
63 /* Check flags */
65 {
66 TRACE("Unknown flags: 0x%08lx\n", InstallFlags & ~(INSTALLFLAG_FORCE | INSTALLFLAG_READONLY | INSTALLFLAG_NONINTERACTIVE));
68 goto cleanup;
69 }
70
71 /* Enumerate all devices of the system */
73 if (DevInstData.hDevInfo == INVALID_HANDLE_VALUE)
74 goto cleanup;
75 DevInstData.devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
76 for (i = 0; ; i++)
77 {
78 if (!SetupDiEnumDeviceInfo(DevInstData.hDevInfo, i, &DevInstData.devInfoData))
79 {
81 {
82 TRACE("SetupDiEnumDeviceInfo() failed with error 0x%x\n", GetLastError());
83 goto cleanup;
84 }
85 /* This error was expected */
86 break;
87 }
88
89 /* Get Hardware ID */
91 Buffer = NULL;
92 BufferSize = 0;
94 DevInstData.hDevInfo,
95 &DevInstData.devInfoData,
97 NULL,
100 &BufferSize))
101 {
103 {
104 Buffer = NULL;
105 break;
106 }
108 {
109 TRACE("SetupDiGetDeviceRegistryPropertyW() failed with error 0x%x\n", GetLastError());
110 goto cleanup;
111 }
112 /* This error was expected */
115 if (!Buffer)
116 {
117 TRACE("HeapAlloc() failed\n", GetLastError());
119 goto cleanup;
120 }
121 }
122 if (Buffer == NULL)
123 continue;
124
125 /* Check if we match the given hardware ID */
126 FoundHardwareId = FALSE;
127 for (CurrentHardwareId = Buffer; *CurrentHardwareId != UNICODE_NULL; CurrentHardwareId += wcslen(CurrentHardwareId) + 1)
128 {
129 if (wcscmp(CurrentHardwareId, HardwareId) == 0)
130 {
131 FoundHardwareId = TRUE;
132 break;
133 }
134 }
135 if (!FoundHardwareId)
136 continue;
137
138 /* We need to try to update the driver of this device */
139
140 /* Get Instance ID */
142 Buffer = NULL;
143 if (SetupDiGetDeviceInstanceIdW(DevInstData.hDevInfo, &DevInstData.devInfoData, NULL, 0, &BufferSize))
144 {
145 /* Error, as the output buffer should be too small */
147 goto cleanup;
148 }
150 {
151 TRACE("SetupDiGetDeviceInstanceIdW() failed with error 0x%x\n", GetLastError());
152 goto cleanup;
153 }
154 else if ((Buffer = HeapAlloc(GetProcessHeap(), 0, BufferSize * sizeof(WCHAR))) == NULL)
155 {
156 TRACE("HeapAlloc() failed\n", GetLastError());
158 goto cleanup;
159 }
160 else if (!SetupDiGetDeviceInstanceIdW(DevInstData.hDevInfo, &DevInstData.devInfoData, Buffer, BufferSize, NULL))
161 {
162 TRACE("SetupDiGetDeviceInstanceIdW() failed with error 0x%x\n", GetLastError());
163 goto cleanup;
164 }
165 TRACE("Trying to update the driver of %s\n", debugstr_w(Buffer));
166
167 /* Search driver in the specified .inf file */
168 if (!SearchDriver(&DevInstData, NULL, FullInfPath))
169 {
170 TRACE("SearchDriver() failed with error 0x%x\n", GetLastError());
171 continue;
172 }
173
174 /* FIXME: HACK! We shouldn't check of ERROR_PRIVILEGE_NOT_HELD */
175 //if (!InstallCurrentDriver(&DevInstData))
177 {
178 TRACE("InstallCurrentDriver() failed with error 0x%x\n", GetLastError());
179 continue;
180 }
181
182 FoundAtLeastOneDevice = TRUE;
183 }
184
185 if (FoundAtLeastOneDevice)
186 {
188 ret = TRUE;
189 }
190 else
191 {
192 TRACE("No device found with HardwareID %s\n", debugstr_w(HardwareId));
194 }
195
196cleanup:
197 if (DevInstData.hDevInfo != INVALID_HANDLE_VALUE)
200 return ret;
201}
#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:307
#define DIGCF_ALLCLASSES
Definition: setupapi.h:172
#define DIGCF_PRESENT
Definition: setupapi.h:171
#define SPDRP_HARDWAREID
Definition: setupapi.h:508
_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().