void CNdasDDUService::OnDevNodesChanged() { #ifdef NDAS_DDUS_USE_DEVICE_EVENTS if (IsDeviceInstallInProgress()) { DebugPrint(1, _T("Warning! Device Installation is in progress!\n")); DebugPrint(1, _T("Sleeping 1 sec.\n")); ::Sleep(1000); } ::NdasDiEnumUnconfigedDevices( _T("NDAS\\SCSIAdapter_R01"), ProcessUnconfigedDevice, NULL); #endif }
BOOL CALLBACK ProcessUnconfigedDevice(LPCTSTR devInstID, LPVOID lpContext) { DebugPrint(1, _T("Un-configured device: %s\n"), devInstID); if (IsDeviceInstallInProgress()) { DebugPrint(1, _T("Warning! Device Installation is in progress!\n")); DebugPrint(1, _T("Sleeping 1 sec.\n")); ::Sleep(1000); } NdasDiInstallDeviceDriver( &GUID_DEVCLASS_SCSIADAPTER, devInstID, _T("C:\\Program Files\\NDAS\\Drivers\\ndasscsi.inf")); // We need a gap! ::Sleep(1000); return TRUE; }
INT WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd ) { LPWSTR *ArgList; INT NumArgs; WCHAR MediaRootDirectory[MAX_PATH]; LPWSTR FileNamePart; DWORD DirPathLength; g_hInstance = hInstance; UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(nShowCmd); // // Windows 2000 doesn't suppress auto-run applications when media (e.g., // a CD) is inserted while a "Found New Hardware" popup is onscreen. This // means that, by default, inserting a CD in order to supply PnP with the // necessary INF and driver files will result in the autorun app launching, // and obscuring the wizard, causing user confusion, etc. // // To avoid this, we retrieve an entrypoint to a Windows 2000 (and later) // Configuration Manager (CM) API that allows us to detect when a device // installation is in-progress, and suppress our own application from // starting. // if(IsDeviceInstallInProgress()) { // // We don't want to startup right now. Don't worry--the value-added // software part of the device installation will be invoked (if // necessary) by our device co-installer during finish-install // processing. // return 0; } // // Retrieve the full directory path from which our setup program was // invoked. // ArgList = CommandLineToArgvW(GetCommandLine(), &NumArgs); if(ArgList && (NumArgs >= 1)) { DirPathLength = GetFullPathName(ArgList[0], MAX_PATH, MediaRootDirectory, &FileNamePart ); if(DirPathLength >= MAX_PATH) { // // The directory is too large for our buffer. Set our directory // path length to zero so we'll simply bail out in this rare case. // DirPathLength = 0; } if(DirPathLength) { // // Strip the filename off the path. // *FileNamePart = L'\0'; DirPathLength = (DWORD)(FileNamePart - MediaRootDirectory); } } else { // // For some reason, we couldn't get the command line arguments that // were used when invoking our setup app. Assume current directory // instead. // DirPathLength = GetCurrentDirectory(MAX_PATH, MediaRootDirectory); if(DirPathLength >= MAX_PATH) { // // The current directory is too large for our buffer. Set our // directory path length to zero so we'll simply bail out in this // rare case. // DirPathLength = 0; } if(DirPathLength) { // // Ensure that path ends in a path separator character. // if((MediaRootDirectory[DirPathLength-1] != L'\\') && (MediaRootDirectory[DirPathLength-1] != L'/')) { MediaRootDirectory[DirPathLength++] = L'\\'; if(DirPathLength < MAX_PATH) { MediaRootDirectory[DirPathLength] = L'\0'; } else { // // Not enough room in buffer to add path separator char // DirPathLength = 0; } } } } if(ArgList) { GlobalFree(ArgList); } if(!DirPathLength) { // // Couldn't figure out what the root directory of our installation // media was. Bail out. // return 0; } // // If we're being invoked from a platform-specific subdirectory (i.e., // \i386 or \ia64), then strip off that subdirectory to get the true media // root path. // if(DirPathLength > TOASTVA_PLATFORM_SUBDIRECTORY_SIZE) { // // We know that the last character in our MediaRootDirectory string is // a path separator character. Check to see if the preceding // characters match our platform-specific subdirectory. // if(!_wcsnicmp(&(MediaRootDirectory[DirPathLength - TOASTVA_PLATFORM_SUBDIRECTORY_SIZE]), TOASTVA_PLATFORM_SUBDIRECTORY, TOASTVA_PLATFORM_SUBDIRECTORY_SIZE - 1)) { // // Platform-specific part matches, just make sure preceding char // is a path separator char. // if((MediaRootDirectory[DirPathLength - TOASTVA_PLATFORM_SUBDIRECTORY_SIZE - 1] == L'\\') || (MediaRootDirectory[DirPathLength - TOASTVA_PLATFORM_SUBDIRECTORY_SIZE - 1] == L'/')) { MediaRootDirectory[DirPathLength - TOASTVA_PLATFORM_SUBDIRECTORY_SIZE] = L'\0'; } } } DoValueAddWizard(MediaRootDirectory); return 0; }