Changeset 37289 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt
- Timestamp:
- Jun 1, 2011 11:59:23 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp
r36487 r37289 50 50 static VOID DoLogging(LPCSTR szString, ...); 51 51 #define Log DoLogging 52 #define LogFlow(x) DoLogging x 52 53 53 54 #define DbgLog … … 57 58 58 59 static HRESULT vboxNetCfgWinINetCfgLock(IN INetCfg *pNetCfg, 59 IN LPCWSTR pszwClientDescription,60 IN DWORD cmsTimeout,61 OUT LPWSTR *ppszwClientDescription)60 IN LPCWSTR pszwClientDescription, 61 IN DWORD cmsTimeout, 62 OUT LPWSTR *ppszwClientDescription) 62 63 { 63 64 INetCfgLock *pLock; 64 65 HRESULT hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock); 65 Assert(hr == S_OK); 66 if (hr != S_OK) 67 { 68 Log(__FUNCTION__ ": QueryInterface failed, hr (0x%x)\n", hr); 66 if (FAILED(hr)) 67 { 68 LogFlow(("QueryInterface failed, hr (0x%x)\n", hr)); 69 69 return hr; 70 70 } 71 71 72 72 hr = pLock->AcquireWriteLock(cmsTimeout, pszwClientDescription, ppszwClientDescription); 73 Assert(hr == S_OK || hr == S_FALSE);74 73 if (hr == S_FALSE) 75 74 { 76 Log (__FUNCTION__ ": write lock busy\n");77 } 78 else if ( hr != S_OK)79 { 80 Log (__FUNCTION__ ": AcquireWriteLock failed hr (0x%x)\n", hr);75 LogFlow(("Write lock busy\n")); 76 } 77 else if (FAILED(hr)) 78 { 79 LogFlow(("AcquireWriteLock failed, hr (0x%x)\n", hr)); 81 80 } 82 81 … … 89 88 INetCfgLock *pLock; 90 89 HRESULT hr = pNetCfg->QueryInterface(IID_INetCfgLock, (PVOID*)&pLock); 91 Assert(hr == S_OK); 92 if (hr != S_OK) 93 { 94 Log(__FUNCTION__ ": QueryInterface failed, hr (0x%x)\n", hr); 90 if (FAILED(hr)) 91 { 92 LogFlow(("QueryInterface failed, hr (0x%x)\n", hr)); 95 93 return hr; 96 94 } 97 95 98 96 hr = pLock->ReleaseWriteLock(); 99 Assert(hr == S_OK); 100 if (hr != S_OK) 101 { 102 Log(__FUNCTION__ ": ReleaseWriteLock failed hr (0x%x)\n", hr); 103 } 97 if (FAILED(hr)) 98 LogFlow(("ReleaseWriteLock failed, hr (0x%x)\n", hr)); 104 99 105 100 pLock->Release(); … … 108 103 109 104 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinQueryINetCfg(OUT INetCfg **ppNetCfg, 110 IN BOOL fGetWriteLock,111 IN LPCWSTR pszwClientDescription,112 IN DWORD cmsTimeout,113 OUT LPWSTR *ppszwClientDescription)105 IN BOOL fGetWriteLock, 106 IN LPCWSTR pszwClientDescription, 107 IN DWORD cmsTimeout, 108 OUT LPWSTR *ppszwClientDescription) 114 109 { 115 110 INetCfg *pNetCfg; 116 111 HRESULT hr = CoCreateInstance(CLSID_CNetCfg, NULL, CLSCTX_INPROC_SERVER, IID_INetCfg, (PVOID*)&pNetCfg); 117 Assert(hr == S_OK); 118 if (hr != S_OK) 119 { 120 Log(__FUNCTION__ ": CoCreateInstance failed, hr (0x%x)\n", hr); 112 if (FAILED(hr)) 113 { 114 LogFlow(("CoCreateInstance failed, hr (0x%x)\n", hr)); 121 115 return hr; 122 116 } … … 125 119 { 126 120 hr = vboxNetCfgWinINetCfgLock(pNetCfg, pszwClientDescription, cmsTimeout, ppszwClientDescription); 127 Assert(hr == S_OK || hr == S_FALSE);128 121 if (hr == S_FALSE) 129 122 { 130 Log (__FUNCTION__ ": write lock is busy\n", hr);123 LogFlow(("Write lock is busy\n", hr)); 131 124 hr = NETCFG_E_NO_WRITE_LOCK; 132 125 } 133 126 } 134 127 135 if ( hr == S_OK)128 if (SUCCEEDED(hr)) 136 129 { 137 130 hr = pNetCfg->Initialize(NULL); 138 Assert(hr == S_OK); 139 if (hr == S_OK) 131 if (SUCCEEDED(hr)) 140 132 { 141 133 *ppNetCfg = pNetCfg; … … 143 135 } 144 136 else 145 { 146 Log(__FUNCTION__ ": Initialize failed, hr (0x%x)\n", hr); 147 } 137 LogFlow(("Initialize failed, hr (0x%x)\n", hr)); 148 138 } 149 139 … … 155 145 { 156 146 HRESULT hr = pNetCfg->Uninitialize(); 157 Assert(hr == S_OK); 158 if (hr != S_OK) 159 { 160 Log(__FUNCTION__ ": Uninitialize failed, hr (0x%x)\n", hr); 147 if (FAILED(hr)) 148 { 149 LogFlow(("Uninitialize failed, hr (0x%x)\n", hr)); 161 150 return hr; 162 151 } … … 165 154 { 166 155 hr = vboxNetCfgWinINetCfgUnlock(pNetCfg); 167 Assert(hr == S_OK); 168 if (hr != S_OK) 169 { 170 Log(__FUNCTION__ ": vboxNetCfgWinINetCfgUnlock failed, hr (0x%x)\n", hr); 171 } 156 if (FAILED(hr)) 157 LogFlow(("vboxNetCfgWinINetCfgUnlock failed, hr (0x%x)\n", hr)); 172 158 } 173 159 … … 176 162 } 177 163 178 static HRESULT vboxNetCfgWinGetComponentByGuidEnum(IEnumNetCfgComponent *pEnumNcc, IN const GUID * pGuid, OUT INetCfgComponent ** ppNcc) 179 { 180 INetCfgComponent * pNcc; 181 GUID NccGuid; 182 164 static HRESULT vboxNetCfgWinGetComponentByGuidEnum(IEnumNetCfgComponent *pEnumNcc, 165 IN const GUID *pGuid, 166 OUT INetCfgComponent **ppNcc) 167 { 183 168 HRESULT hr = pEnumNcc->Reset(); 184 Assert(hr == S_OK); 185 if (hr != S_OK) 186 { 187 Log(__FUNCTION__": Reset failed, hr (0x%x)\n", hr); 169 if (FAILED(hr)) 170 { 171 LogFlow(("Reset failed, hr (0x%x)\n", hr)); 188 172 return hr; 189 173 } 190 174 175 INetCfgComponent *pNcc; 191 176 while ((hr = pEnumNcc->Next(1, &pNcc, NULL)) == S_OK) 192 177 { 193 178 ULONG uComponentStatus; 194 179 hr = pNcc->GetDeviceStatus(&uComponentStatus); 195 if ( hr == S_OK)180 if (SUCCEEDED(hr)) 196 181 { 197 182 if (uComponentStatus == 0) 198 183 { 184 GUID NccGuid; 199 185 hr = pNcc->GetInstanceGuid(&NccGuid); 200 Assert(hr == S_OK); 201 if ( hr == S_OK)186 187 if (SUCCEEDED(hr)) 202 188 { 203 189 if (NccGuid == *pGuid) … … 209 195 } 210 196 else 211 { 212 Log(__FUNCTION__": GetInstanceGuid failed, hr (0x%x)\n", hr); 213 } 197 LogFlow(("GetInstanceGuid failed, hr (0x%x)\n", hr)); 214 198 } 215 199 } … … 217 201 pNcc->Release(); 218 202 } 219 220 Assert(hr == S_OK || hr == S_FALSE); 221 return hr; 222 } 223 224 VBOXNETCFGWIN_DECL(HRESULT) 225 VBoxNetCfgWinGetComponentByGuid(IN INetCfg *pNc, 226 IN const GUID *pguidClass, 227 IN const GUID * pComponentGuid, 228 OUT INetCfgComponent **ppncc) 203 return hr; 204 } 205 206 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGetComponentByGuid(IN INetCfg *pNc, 207 IN const GUID *pguidClass, 208 IN const GUID * pComponentGuid, 209 OUT INetCfgComponent **ppncc) 229 210 { 230 211 IEnumNetCfgComponent *pEnumNcc; 231 212 HRESULT hr = pNc->EnumComponents(pguidClass, &pEnumNcc); 232 Assert(hr == S_OK); 233 if ( hr == S_OK)213 214 if (SUCCEEDED(hr)) 234 215 { 235 216 hr = vboxNetCfgWinGetComponentByGuidEnum(pEnumNcc, pComponentGuid, ppncc); 236 Assert(hr == S_OK || hr == S_FALSE);237 217 if (hr == S_FALSE) 238 218 { 239 Log (__FUNCTION__": component not found \n");240 } 241 else if ( hr != S_OK)242 { 243 Log (__FUNCTION__": vboxNetCfgWinGetComponentByGuidEnum failed, hr (0x%x)\n", hr);219 LogFlow(("Component not found\n")); 220 } 221 else if (FAILED(hr)) 222 { 223 LogFlow(("vboxNetCfgWinGetComponentByGuidEnum failed, hr (0x%x)\n", hr)); 244 224 } 245 225 pEnumNcc->Release(); 246 226 } 247 227 else 248 { 249 Log(__FUNCTION__": EnumComponents failed, hr (0x%x)\n", hr); 250 } 228 LogFlow(("EnumComponents failed, hr (0x%x)\n", hr)); 251 229 return hr; 252 230 } … … 255 233 { 256 234 HRESULT hr = pNetCfg->QueryNetCfgClass(pguidClass, IID_INetCfgClassSetup, (void**)ppSetup); 257 Assert(hr == S_OK); 258 if (hr != S_OK) 259 { 260 Log(__FUNCTION__ ": QueryNetCfgClass failed hr (0x%x)\n", hr); 261 } 235 if (FAILED(hr)) 236 LogFlow(("QueryNetCfgClass failed, hr (0x%x)\n", hr)); 262 237 return hr; 263 238 } 264 239 265 240 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinInstallComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass, 266 OUT INetCfgComponent **ppComponent)241 OUT INetCfgComponent **ppComponent) 267 242 { 268 243 INetCfgClassSetup *pSetup; 269 244 HRESULT hr = vboxNetCfgWinQueryInstaller(pNetCfg, pguidClass, &pSetup); 270 Assert(hr == S_OK); 271 if (hr != S_OK) 272 { 273 Log(__FUNCTION__ ": vboxNetCfgWinQueryInstaller failed hr (0x%x)\n", hr); 245 if (FAILED(hr)) 246 { 247 LogFlow(("vboxNetCfgWinQueryInstaller failed, hr (0x%x)\n", hr)); 274 248 return hr; 275 249 } 276 250 277 251 OBO_TOKEN Token; 278 memset(&Token, 0, sizeof (Token));252 ZeroMemory(&Token, sizeof (Token)); 279 253 Token.Type = OBO_USER; 280 254 281 255 hr = pSetup->Install(pszwComponentId, &Token, 282 0, /* IN DWORD dwSetupFlags */ 283 0, /* IN DWORD dwUpgradeFromBuildNo */ 284 NULL, /* IN LPCWSTR pszwAnswerFile */ 285 NULL, /* IN LPCWSTR pszwAnswerSections */ 286 ppComponent); 287 Assert(hr == S_OK); 288 if (hr == S_OK) 256 0, /* IN DWORD dwSetupFlags */ 257 0, /* IN DWORD dwUpgradeFromBuildNo */ 258 NULL, /* IN LPCWSTR pszwAnswerFile */ 259 NULL, /* IN LPCWSTR pszwAnswerSections */ 260 ppComponent); 261 if (SUCCEEDED(hr)) 289 262 { 290 263 /* ignore the apply failure */ … … 292 265 Assert(tmpHr == S_OK); 293 266 if (tmpHr != S_OK) 294 { 295 Log(__FUNCTION__ ": Apply failed, hr (0x%x)\n", tmpHr); 296 } 267 LogFlow(("Apply failed, hr (0x%x)\n", tmpHr)); 297 268 } 298 269 else 299 { 300 Log(__FUNCTION__ ": Install failed hr (0x%x)\n", hr); 301 } 270 LogFlow(("Install failed, hr (0x%x)\n", hr)); 271 302 272 pSetup->Release(); 303 273 return hr; … … 305 275 306 276 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinInstallInfAndComponent(IN INetCfg *pNetCfg, IN LPCWSTR pszwComponentId, IN const GUID *pguidClass, 307 IN LPCWSTR * apInfPaths, IN UINT cInfPaths,308 OUT INetCfgComponent **ppComponent)277 IN LPCWSTR * apInfPaths, IN UINT cInfPaths, 278 OUT INetCfgComponent **ppComponent) 309 279 { 310 280 HRESULT hr = S_OK; 311 281 UINT i = 0; 312 282 283 LogFlow(("Installing %u INF files ...\n", cInfPaths)); 284 313 285 for (; i < cInfPaths; i++) 314 286 { 287 LogFlow(("Installing INF file \"%ws\" ...\n", apInfPaths[i])); 315 288 hr = VBoxDrvCfgInfInstall(apInfPaths[i]); 316 Assert(hr == S_OK); 317 if (hr != S_OK) 318 { 319 Log(__FUNCTION__ ": VBoxNetCfgWinInfInstall failed hr (0x%x)\n", hr); 289 if (FAILED(hr)) 290 { 291 LogFlow(("VBoxNetCfgWinInfInstall failed, hr (0x%x)\n", hr)); 320 292 break; 321 293 } 322 294 } 323 295 324 if ( hr == S_OK)296 if (SUCCEEDED(hr)) 325 297 { 326 298 hr = VBoxNetCfgWinInstallComponent(pNetCfg, pszwComponentId, pguidClass, ppComponent); 327 Assert(hr == S_OK); 328 if (hr != S_OK) 329 { 330 Log(__FUNCTION__ ": VBoxNetCfgWinInstallComponent failed hr (0x%x)\n", hr); 331 } 332 } 333 334 if (hr != S_OK) 335 { 336 for (UINT j = i-1; j != 0; j--) 337 { 299 if (FAILED(hr)) 300 LogFlow(("VBoxNetCfgWinInstallComponent failed, hr (0x%x)\n", hr)); 301 } 302 303 if (FAILED(hr)) 304 { 305 for (UINT j = i - 1; j != 0; j--) 338 306 VBoxDrvCfgInfUninstall(apInfPaths[j], 0); 339 }340 307 } 341 308 … … 347 314 GUID GuidClass; 348 315 HRESULT hr = pComponent->GetClassGuid(&GuidClass); 349 Assert(hr == S_OK); 350 if (hr != S_OK) 351 { 352 Log(__FUNCTION__ ": GetClassGuid failed hr (0x%x)\n", hr); 316 if (FAILED(hr)) 317 { 318 LogFlow(("GetClassGuid failed, hr (0x%x)\n", hr)); 353 319 return hr; 354 320 } 355 321 356 INetCfgClassSetup *pSetup ;322 INetCfgClassSetup *pSetup = NULL; 357 323 hr = vboxNetCfgWinQueryInstaller(pNetCfg, &GuidClass, &pSetup); 358 Assert(hr == S_OK); 359 if (hr != S_OK) 360 { 361 Log(__FUNCTION__ ": vboxNetCfgWinQueryInstaller failed hr (0x%x)\n", hr); 324 if (FAILED(hr)) 325 { 326 LogFlow(("vboxNetCfgWinQueryInstaller failed, hr (0x%x)\n", hr)); 362 327 return hr; 363 328 } 364 329 365 330 OBO_TOKEN Token; 366 memset(&Token, 0, sizeof(Token));331 ZeroMemory(&Token, sizeof(Token)); 367 332 Token.Type = OBO_USER; 368 333 369 334 hr = pSetup->DeInstall(pComponent, &Token, NULL /* OUT LPWSTR *pmszwRefs */); 370 Assert(hr == S_OK); 371 if (hr == S_OK) 372 { 373 HRESULT tmpHr = pNetCfg->Apply(); 374 Assert(tmpHr == S_OK); 375 if (tmpHr != S_OK) 376 { 377 Log(__FUNCTION__ ": Apply failed, hr (0x%x)\n", tmpHr); 378 } 335 if (SUCCEEDED(hr)) 336 { 337 hr = pNetCfg->Apply(); 338 if (FAILED(hr)) 339 LogFlow(("Apply failed, hr (0x%x)\n", hr)); 379 340 } 380 341 else 381 {382 Log(__FUNCTION__ ": DeInstall failed hr (0x%x)\n", hr); 383 }384 pSetup->Release();385 return hr; 386 } 387 388 typedef BOOL (*VBOXNETCFGWIN_NETCFGENUM_CALLBACK) (IN INetCfg *pN c, IN INetCfgComponent *pNcc, PVOID pContext);389 390 static HRESULT vboxNetCfgWinEnumNetCfgComponents(IN INetCfg *pN c,391 IN const GUID *pguidClass,392 VBOXNETCFGWIN_NETCFGENUM_CALLBACK callback,393 PVOID pContext)342 LogFlow(("DeInstall failed, hr (0x%x)\n", hr)); 343 344 if (pSetup) 345 pSetup->Release(); 346 return hr; 347 } 348 349 typedef BOOL (*VBOXNETCFGWIN_NETCFGENUM_CALLBACK) (IN INetCfg *pNetCfg, IN INetCfgComponent *pNetCfgComponent, PVOID pContext); 350 351 static HRESULT vboxNetCfgWinEnumNetCfgComponents(IN INetCfg *pNetCfg, 352 IN const GUID *pguidClass, 353 VBOXNETCFGWIN_NETCFGENUM_CALLBACK callback, 354 PVOID pContext) 394 355 { 395 356 IEnumNetCfgComponent *pEnumComponent; 396 HRESULT hr = pNc->EnumComponents(pguidClass, &pEnumComponent); 397 bool bBreak = false; 398 Assert(hr == S_OK); 399 if (hr == S_OK) 400 { 401 INetCfgComponent *pNcc; 357 HRESULT hr = pNetCfg->EnumComponents(pguidClass, &pEnumComponent); 358 if (SUCCEEDED(hr)) 359 { 360 INetCfgComponent *pNetCfgComponent; 402 361 hr = pEnumComponent->Reset(); 403 Assert(hr == S_OK);404 362 do 405 363 { 406 hr = pEnumComponent->Next(1, &pNcc, NULL); 407 Assert(hr == S_OK || hr == S_FALSE); 408 if (hr == S_OK) 364 hr = pEnumComponent->Next(1, &pNetCfgComponent, NULL); 365 if (SUCCEEDED(hr)) 409 366 { 410 367 // ULONG uComponentStatus; 411 368 // hr = pNcc->GetDeviceStatus(&uComponentStatus); 412 // if (hr == S_OK) 413 { 414 if (!callback(pNc, pNcc, pContext)) 415 { 416 bBreak = true; 417 } 418 } 419 pNcc->Release(); 369 // if (SUCCEEDED(hr)) 370 BOOL fResult = FALSE; 371 if (pNetCfgComponent) 372 { 373 if (pContext) 374 fResult = callback(pNetCfg, pNetCfgComponent, pContext); 375 pNetCfgComponent->Release(); 376 } 377 378 if (!fResult) 379 break; 420 380 } 421 381 else 422 382 { 423 if (hr == S_FALSE)383 if (hr == S_FALSE) 424 384 { 425 385 hr = S_OK; 426 386 } 427 387 else 428 { 429 Log(__FUNCTION__": Next failed, hr (0x%x)\n", hr); 430 } 388 LogFlow(("Next failed, hr (0x%x)\n", hr)); 431 389 break; 432 390 } 433 } while (!bBreak); 434 391 } while (true); 435 392 pEnumComponent->Release(); 436 393 } … … 440 397 static BOOL vboxNetCfgWinRemoveAllNetDevicesOfIdCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext) 441 398 { 442 DWORD winEr;443 399 HRESULT hr = S_OK; 444 400 SP_REMOVEDEVICE_PARAMS rmdParams; 401 445 402 rmdParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); 446 403 rmdParams.ClassInstallHeader.InstallFunction = DIF_REMOVE; 447 404 rmdParams.Scope = DI_REMOVEDEVICE_GLOBAL; 448 405 rmdParams.HwProfile = 0; 406 449 407 if (SetupDiSetClassInstallParams(hDevInfo,pDev,&rmdParams.ClassInstallHeader,sizeof(rmdParams))) 450 408 { … … 460 418 { 461 419 hr = S_FALSE; 462 Log( __FUNCTION__": !!!REBOOT REQUIRED!!!\n");420 Log(("!!!REBOOT REQUIRED!!!\n")); 463 421 } 464 422 } … … 466 424 else 467 425 { 468 winEr = GetLastError();469 Log (__FUNCTION__": SetupDiCallClassInstaller failed winErr(%d)\n", winEr);470 hr = HRESULT_FROM_WIN32( winEr);426 DWORD dwErr = GetLastError(); 427 LogFlow(("SetupDiCallClassInstaller failed with %ld\n", dwErr)); 428 hr = HRESULT_FROM_WIN32(dwErr); 471 429 } 472 430 } 473 431 else 474 432 { 475 winEr = GetLastError();476 Log (__FUNCTION__": SetupDiSetSelectedDevice failed winErr(%d)\n", winEr);477 hr = HRESULT_FROM_WIN32( winEr);433 DWORD dwErr = GetLastError(); 434 LogFlow(("SetupDiSetSelectedDevice failed with %ld\n", dwErr)); 435 hr = HRESULT_FROM_WIN32(dwErr); 478 436 } 479 437 } 480 438 else 481 439 { 482 winEr = GetLastError();483 Log (__FUNCTION__": SetupDiSetClassInstallParams failed winErr(%d)\n", winEr);484 hr = HRESULT_FROM_WIN32( winEr);440 DWORD dwErr = GetLastError(); 441 LogFlow(("SetupDiSetClassInstallParams failed with %ld\n", dwErr)); 442 hr = HRESULT_FROM_WIN32(dwErr); 485 443 } 486 444 … … 528 486 if (winEr != ERROR_INSUFFICIENT_BUFFER) 529 487 { 530 Log (__FUNCTION__": SetupDiGetDeviceRegistryPropertyW (1) failed winErr(%d)\n", winEr);488 LogFlow(("SetupDiGetDeviceRegistryPropertyW (1) failed winErr(%d)\n", winEr)); 531 489 hr = HRESULT_FROM_WIN32(winEr); 532 490 break; … … 534 492 535 493 if (pBuffer) 536 {537 494 free(pBuffer); 538 }539 495 540 496 pBuffer = (PBYTE)malloc(cbRequired); … … 542 498 543 499 if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo,&Dev, 544 SPDRP_HARDWAREID, /* IN DWORD Property,*/545 NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/546 pBuffer, /*OUT PBYTE PropertyBuffer,*/547 cbBuffer, /* IN DWORD PropertyBufferSize,*/548 &cbRequired /*OUT PDWORD RequiredSize OPTIONAL*/549 ))500 SPDRP_HARDWAREID, /* IN DWORD Property,*/ 501 NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/ 502 pBuffer, /*OUT PBYTE PropertyBuffer,*/ 503 cbBuffer, /* IN DWORD PropertyBufferSize,*/ 504 &cbRequired /*OUT PDWORD RequiredSize OPTIONAL*/ 505 )) 550 506 { 551 507 winEr = GetLastError(); 552 Log (__FUNCTION__": SetupDiGetDeviceRegistryPropertyW (2) failed winErr(%d)\n", winEr);508 LogFlow(("SetupDiGetDeviceRegistryPropertyW (2) failed winErr(%d)\n", winEr)); 553 509 hr = HRESULT_FROM_WIN32(winEr); 554 510 break; … … 585 541 { 586 542 DWORD winEr = GetLastError(); 587 Log (__FUNCTION__": SetupDiGetClassDevsExW failed winErr(%d)\n", winEr);543 LogFlow(("SetupDiGetClassDevsExW failed winErr(%d)\n", winEr)); 588 544 hr = HRESULT_FROM_WIN32(winEr); 589 545 } … … 868 824 } 869 825 else 870 { 871 Log(__FUNCTION__": ExecQuery fail hr (0x%x)\n", hr); 872 } 826 LogFlow(("ExecQuery failed (0x%x)\n", hr)); 873 827 } 874 828 else 875 829 { 876 830 DWORD winEr = GetLastError(); 877 Log (__FUNCTION__": StringFromGUID2 fail winEr (%d)\n", winEr);831 LogFlow(("StringFromGUID2 failed winEr (%d)\n", winEr)); 878 832 hr = HRESULT_FROM_WIN32( winEr ); 879 833 } … … 1002 956 { 1003 957 if (!wcsicmp(pCurMask, pMask)) 1004 {1005 958 *pFound = true; 1006 }1007 959 break; 1008 960 } … … 1076 1028 } 1077 1029 else 1078 { 1079 Log(__FUNCTION__": CoSetProxyBlanket failed hr (0x%x)\n", hr); 1080 } 1030 LogFlow(("CoSetProxyBlanket failed, hr (0x%x)\n", hr)); 1081 1031 1082 1032 pSvc->Release(); 1083 1033 } 1084 1034 else 1085 { 1086 Log(__FUNCTION__": ConnectServer failed hr (0x%x)\n", hr); 1087 } 1088 1035 LogFlow(("ConnectServer failed, hr (0x%x)\n", hr)); 1089 1036 pLoc->Release(); 1090 1037 } 1091 1038 else 1092 { 1093 Log(__FUNCTION__": CoCreateInstance failed hr (0x%x)\n", hr); 1094 } 1095 1039 LogFlow(("CoCreateInstance failed, hr (0x%x)\n", hr)); 1096 1040 return hr; 1097 1041 } … … 1108 1052 } 1109 1053 else 1110 { 1111 DWORD winEr = GetLastError(); 1112 Log(__FUNCTION__": Get failed winEr (%d)\n", winEr); 1113 Assert(0); 1114 hr = HRESULT_FROM_WIN32(winEr); 1115 } 1054 LogFlow(("Get failed, hr (0x%x)\n", hr)); 1116 1055 return hr; 1117 1056 } … … 1139 1078 pArgs[i], 0); 1140 1079 if (FAILED(hr)) 1141 {1142 1080 break; 1143 }1144 1081 } 1145 1082 } … … 1187 1124 } 1188 1125 else 1189 { 1190 DWORD dwError = GetLastError(); 1191 Assert(0); 1192 hr = HRESULT_FROM_WIN32( dwError ); 1193 } 1126 hr = HRESULT_FROM_WIN32(GetLastError()); 1194 1127 1195 1128 return hr; … … 1218 1151 } 1219 1152 else 1220 { 1221 DWORD dwError = GetLastError(); 1222 Assert(0); 1223 hr = HRESULT_FROM_WIN32( dwError ); 1224 } 1153 hr = HRESULT_FROM_WIN32(GetLastError()); 1225 1154 1226 1155 return hr; … … 1300 1229 } 1301 1230 else 1302 { 1303 DWORD winEr = GetLastError(); 1304 Assert(0); 1305 hr = HRESULT_FROM_WIN32(winEr); 1306 } 1231 hr = HRESULT_FROM_WIN32(GetLastError()); 1307 1232 1308 1233 return hr; … … 1381 1306 } 1382 1307 } 1383 } } 1308 } 1309 } 1384 1310 SysFreeString(ClassName); 1385 1311 } 1386 1312 else 1387 { 1388 DWORD dwError = GetLastError(); 1389 Assert(0); 1390 hr = HRESULT_FROM_WIN32( dwError ); 1391 } 1313 hr = HRESULT_FROM_WIN32(GetLastError()); 1392 1314 1393 1315 return hr; … … 1458 1380 } 1459 1381 else 1460 { 1461 DWORD dwError = GetLastError(); 1462 Assert(0); 1463 hr = HRESULT_FROM_WIN32( dwError ); 1464 } 1382 hr = HRESULT_FROM_WIN32(GetLastError()); 1465 1383 1466 1384 return hr; … … 1502 1420 int winEr = varReturnValue.uintVal; 1503 1421 if (winEr == 0) 1504 {1505 1422 hr = S_OK; 1506 }1507 1423 else 1508 {1509 1424 hr = HRESULT_FROM_WIN32( winEr ); 1510 }1511 1425 } 1512 1426 } 1513 1427 } 1514 1428 else 1515 {1516 1429 hr = HRESULT_FROM_WIN32( winEr ); 1517 }1518 1430 } 1519 1431 } … … 1522 1434 } 1523 1435 else 1524 { 1525 DWORD dwError = GetLastError(); 1526 Assert(0); 1527 hr = HRESULT_FROM_WIN32(dwError); 1528 } 1436 hr = HRESULT_FROM_WIN32(GetLastError()); 1529 1437 1530 1438 return hr; … … 1536 1444 HRESULT hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0); 1537 1445 if (SUCCEEDED(hr)) 1538 {1539 1446 *pEnabled = vtEnabled.boolVal; 1540 }1541 1447 return hr; 1542 1448 } … … 1551 1457 ComPtr <IWbemClassObject> pAdapterConfig; 1552 1458 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1553 if ( hr == S_OK)1459 if (SUCCEEDED(hr)) 1554 1460 { 1555 1461 hr = vboxNetCfgWinIsDhcpEnabled(pAdapterConfig, &pSettings->bDhcp); 1556 1462 if (SUCCEEDED(hr)) 1557 {1558 1463 hr = netIfWinGetIpSettings(pAdapterConfig, &pSettings->ip, &pSettings->mask); 1559 }1560 1464 } 1561 1465 } … … 1573 1477 ComPtr <IWbemClassObject> pAdapterConfig; 1574 1478 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1575 if ( hr == S_OK)1479 if (SUCCEEDED(hr)) 1576 1480 { 1577 1481 VARIANT vtEnabled; 1578 1482 hr = pAdapterConfig->Get(L"DHCPEnabled", 0, &vtEnabled, 0, 0); 1579 1483 if (SUCCEEDED(hr)) 1580 {1581 1484 *pEnabled = vtEnabled.boolVal; 1582 }1583 1485 } 1584 1486 } … … 1596 1498 ComPtr <IWbemClassObject> pAdapterConfig; 1597 1499 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1598 if ( hr == S_OK)1500 if (SUCCEEDED(hr)) 1599 1501 { 1600 1502 BOOL bIsHostOnly; … … 1649 1551 ComPtr <IWbemClassObject> pAdapterConfig; 1650 1552 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1651 if ( hr == S_OK)1553 if (SUCCEEDED(hr)) 1652 1554 { 1653 1555 BSTR ObjPath; … … 1697 1599 ComPtr <IWbemClassObject> pAdapterConfig; 1698 1600 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1699 if ( hr == S_OK)1601 if (SUCCEEDED(hr)) 1700 1602 { 1701 1603 BOOL bIsHostOnly; … … 1738 1640 ComPtr <IWbemClassObject> pAdapterConfig; 1739 1641 hr = netIfWinFindAdapterClassById(pSvc, pGuid, pAdapterConfig.asOutParam()); 1740 if ( hr == S_OK)1642 if (SUCCEEDED(hr)) 1741 1643 { 1742 1644 BOOL bIsHostOnly; … … 1902 1804 } 1903 1805 else 1904 {1905 Log(__FUNCTION__": GetAdaptersAddresses err (%d)\n", dwRc); 1906 }1907 free(pAddresses);1806 LogFlow(("GetAdaptersAddresses err (%d)\n", dwRc)); 1807 1808 if (pAddresses) 1809 free(pAddresses); 1908 1810 1909 1811 if (dwRc != NO_ERROR) … … 1927 1829 if (hr == S_OK) 1928 1830 { 1929 Log("NetFlt Is Installed currently\n");1831 Log("NetFlt is installed currently, uninstalling ...\n"); 1930 1832 1931 1833 hr = VBoxNetCfgWinUninstallComponent(pNc, pNcc); … … 1935 1837 else if (hr == S_FALSE) 1936 1838 { 1937 Log("NetFlt Is Not Installed currently\n");1839 Log("NetFlt is not installed currently\n"); 1938 1840 hr = S_OK; 1939 1841 } 1940 1842 else 1941 1843 { 1942 Log ("vboxNetCfgWinNetFltUninstall: FindComponent for NetFlt failed, hr (0x%x)\n", hr);1844 LogFlow(("FindComponent failed, hr (0x%x)\n", hr)); 1943 1845 hr = S_OK; 1944 1846 } … … 1950 1852 } 1951 1853 1952 VBOXNETCFGWIN_DECL(HRESULT) 1953 VBoxNetCfgWinNetFltUninstall(IN INetCfg *pNc) 1854 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltUninstall(IN INetCfg *pNc) 1954 1855 { 1955 1856 return vboxNetCfgWinNetFltUninstall(pNc, 0); 1956 1857 } 1957 1858 1958 VBOXNETCFGWIN_DECL(HRESULT) 1959 VBoxNetCfgWinNetFltInstall(IN INetCfg *pNc,IN LPCWSTR * apInfFullPaths, IN UINT cInfFullPaths)1859 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinNetFltInstall(IN INetCfg *pNc, 1860 IN LPCWSTR * apInfFullPaths, IN UINT cInfFullPaths) 1960 1861 { 1961 1862 HRESULT hr = vboxNetCfgWinNetFltUninstall(pNc, SUOI_FORCEDELETE); 1962 1963 hr = VBoxNetCfgWinInstallInfAndComponent(pNc, VBOXNETCFGWIN_NETFLT_ID, 1964 &GUID_DEVCLASS_NETSERVICE, 1965 apInfFullPaths, 1966 cInfFullPaths, 1967 NULL); 1968 1863 if (SUCCEEDED(hr)) 1864 { 1865 Log("NetFlt will be installed ...\n"); 1866 hr = VBoxNetCfgWinInstallInfAndComponent(pNc, VBOXNETCFGWIN_NETFLT_ID, 1867 &GUID_DEVCLASS_NETSERVICE, 1868 apInfFullPaths, 1869 cInfFullPaths, 1870 NULL); 1871 } 1969 1872 return hr; 1970 1873 } 1971 1874 1972 1875 #define VBOX_CONNECTION_NAME L"VirtualBox Host-Only Network" 1973 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostonlyConnectionName 1876 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostonlyConnectionName(PCWSTR DevName, WCHAR *pBuf, PULONG pcbBuf) 1974 1877 { 1975 1878 const WCHAR * pSuffix = wcsrchr( DevName, L'#' ); … … 1999 1902 } 2000 1903 2001 static BOOL vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority (IN INetCfg *pNc, IN INetCfgComponent *pNcc, PVOID pContext) 2002 { 2003 INetCfgComponentBindings *pNccb = NULL; 2004 IEnumNetCfgBindingPath *pEnumNccbp; 1904 static BOOL vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority(IN INetCfg *pNc, IN INetCfgComponent *pNcc, PVOID pContext) 1905 { 1906 INetCfgComponentBindings *pNetCfgBindings; 2005 1907 GUID *pGuid = (GUID*)pContext; 2006 HRESULT hr;2007 bool bFound = false;2008 1908 2009 1909 /* Get component's binding. */ 2010 hr = pNcc->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pNccb); 2011 Assert(hr == S_OK); 2012 if ( hr == S_OK ) 1910 HRESULT hr = pNcc->QueryInterface(IID_INetCfgComponentBindings, (PVOID*)&pNetCfgBindings); 1911 if (SUCCEEDED(hr)) 2013 1912 { 2014 1913 /* Get binding path enumerator reference. */ 2015 hr = pNccb->EnumBindingPaths(EBP_BELOW, &pEnumNccbp); 2016 Assert(hr == S_OK); 2017 if (hr == S_OK) 2018 { 2019 INetCfgBindingPath *pNccbp; 2020 hr = pEnumNccbp->Reset(); 2021 Assert(hr == S_OK); 1914 IEnumNetCfgBindingPath *pEnumNetCfgBindPath; 1915 hr = pNetCfgBindings->EnumBindingPaths(EBP_BELOW, &pEnumNetCfgBindPath); 1916 if (SUCCEEDED(hr)) 1917 { 1918 bool bFoundIface = false; 1919 hr = pEnumNetCfgBindPath->Reset(); 2022 1920 do 2023 1921 { 2024 hr = pEnumNccbp->Next(1, &pNccbp, NULL);2025 Assert(hr == S_OK || hr == S_FALSE);1922 INetCfgBindingPath *pNetCfgBindPath; 1923 hr = pEnumNetCfgBindPath->Next(1, &pNetCfgBindPath, NULL); 2026 1924 if (hr == S_OK) 2027 1925 { 2028 // if (pNccbp->IsEnabled() == S_OK) 1926 IEnumNetCfgBindingInterface *pEnumNetCfgBindIface; 1927 hr = pNetCfgBindPath->EnumBindingInterfaces(&pEnumNetCfgBindIface); 1928 if (hr == S_OK) 2029 1929 { 2030 IEnumNetCfgBindingInterface *pEnumNcbi; 2031 hr = pNccbp->EnumBindingInterfaces(&pEnumNcbi); 2032 Assert(hr == S_OK); 2033 if (hr == S_OK) 1930 pEnumNetCfgBindIface->Reset(); 1931 do 2034 1932 { 2035 INetCfgBindingInterface *pNcbi; 2036 hr = pEnumNcbi->Reset(); 2037 Assert(hr == S_OK); 2038 do 1933 INetCfgBindingInterface *pNetCfgBindIfce; 1934 hr = pEnumNetCfgBindIface->Next(1, &pNetCfgBindIfce, NULL); 1935 if (hr == S_OK) 2039 1936 { 2040 hr = pEnumNcbi->Next(1, &pNcbi, NULL);2041 Assert(hr == S_OK || hr == S_FALSE);1937 INetCfgComponent *pNetCfgCompo; 1938 hr = pNetCfgBindIfce->GetLowerComponent(&pNetCfgCompo); 2042 1939 if (hr == S_OK) 2043 1940 { 2044 INetCfgComponent * pNccBoud; 2045 hr = pNcbi->GetLowerComponent(&pNccBoud); 2046 Assert(hr == S_OK); 1941 ULONG uComponentStatus; 1942 hr = pNetCfgCompo->GetDeviceStatus(&uComponentStatus); 2047 1943 if (hr == S_OK) 2048 1944 { 2049 ULONG uComponentStatus; 2050 hr = pNccBoud->GetDeviceStatus(&uComponentStatus); 2051 if (hr == S_OK) 1945 GUID guid; 1946 hr = pNetCfgCompo->GetInstanceGuid(&guid); 1947 if ( hr == S_OK 1948 && guid == *pGuid) 2052 1949 { 2053 // if (uComponentStatus == 0) 2054 { 2055 GUID guid; 2056 hr = pNccBoud->GetInstanceGuid(&guid); 2057 if (guid == *pGuid) 2058 { 2059 hr = pNccb->MoveAfter(pNccbp, NULL); 2060 Assert(hr == S_OK); 2061 bFound = true; 2062 } 2063 } 1950 hr = pNetCfgBindings->MoveAfter(pNetCfgBindPath, NULL); 1951 if (FAILED(hr)) 1952 LogFlow(("Unable to move interface, hr (0x%x)\n", hr)); 1953 bFoundIface = true; 2064 1954 } 2065 pNccBoud->Release();2066 1955 } 2067 pN cbi->Release();1956 pNetCfgCompo->Release(); 2068 1957 } 2069 1958 else 2070 { 2071 if (hr == S_FALSE) 2072 { 2073 hr = S_OK; 2074 } 2075 else 2076 { 2077 Log(__FUNCTION__": Next failed, hr (0x%x)\n", hr); 2078 } 2079 break; 2080 } 2081 } while (!bFound); 2082 pEnumNcbi->Release(); 2083 } 2084 else 2085 { 2086 Log(__FUNCTION__": EnumBindingInterfaces failed, hr (0x%x)\n", hr); 2087 } 2088 } 2089 2090 pNccbp->Release(); 2091 } 2092 else 2093 { 2094 if (hr = S_FALSE) 2095 { 2096 hr = S_OK; 1959 LogFlow(("GetLowerComponent failed, hr (0x%x)\n", hr)); 1960 pNetCfgBindIfce->Release(); 1961 } 1962 else 1963 { 1964 if (hr == S_FALSE) /* No more binding interfaces? */ 1965 hr = S_OK; 1966 else 1967 LogFlow(("Next binding interface failed, hr (0x%x)\n", hr)); 1968 break; 1969 } 1970 } while (!bFoundIface); 1971 pEnumNetCfgBindIface->Release(); 2097 1972 } 2098 1973 else 2099 { 2100 Log(__FUNCTION__": Next failed, hr (0x%x)\n", hr); 2101 } 1974 LogFlow(("EnumBindingInterfaces failed, hr (0x%x)\n", hr)); 1975 pNetCfgBindPath->Release(); 1976 } 1977 else 1978 { 1979 if (hr = S_FALSE) /* No more binding paths? */ 1980 hr = S_OK; 1981 else 1982 LogFlow(("Next bind path failed, hr (0x%x)\n", hr)); 2102 1983 break; 2103 1984 } 2104 } while (!bFound); 2105 2106 pEnumNccbp->Release(); 1985 } while (!bFoundIface); 1986 pEnumNetCfgBindPath->Release(); 2107 1987 } 2108 1988 else 2109 { 2110 Log(__FUNCTION__": EnumBindingPaths failed, hr (0x%x)\n", hr); 2111 } 2112 2113 pNccb->Release(); 1989 LogFlow(("EnumBindingPaths failed, hr (0x%x)\n", hr)); 1990 pNetCfgBindings->Release(); 2114 1991 } 2115 1992 else 2116 { 2117 Log(__FUNCTION__": QueryInterface for IID_INetCfgComponentBindings failed, hr (0x%x)\n", hr); 2118 } 2119 2120 return true; 1993 LogFlow(("QueryInterface for IID_INetCfgComponentBindings failed, hr (0x%x)\n", hr)); 1994 return TRUE; 2121 1995 } 2122 1996 … … 2257 2131 hrc = E_FAIL; \ 2258 2132 Log strAndArgs; \ 2259 Assert(0); \2260 2133 break; \ 2261 2134 } else do {} while (0) 2262 2135 2263 2264 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRemoveHostOnlyNetworkInterface (IN const GUID *pGUID, OUT BSTR *pErrMsg) 2136 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRemoveHostOnlyNetworkInterface(IN const GUID *pGUID, OUT BSTR *pErrMsg) 2265 2137 { 2266 2138 HRESULT hrc = S_OK; … … 2467 2339 } 2468 2340 2469 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface 2470 OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg)2341 VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinCreateHostOnlyNetworkInterface(IN LPCWSTR pInfPath, IN bool bIsInfPathFile, 2342 OUT GUID *pGuid, OUT BSTR *lppszName, OUT BSTR *pErrMsg) 2471 2343 { 2472 2344 HRESULT hrc = S_OK; … … 2484 2356 do 2485 2357 { 2486 BOOL ok;2487 2358 GUID netGuid; 2488 2359 SP_DRVINFO_DATA DriverInfoData; … … 2508 2379 2509 2380 /* create an empty device info set associated with the net class GUID */ 2510 hDeviceInfo = SetupDiCreateDeviceInfoList 2381 hDeviceInfo = SetupDiCreateDeviceInfoList(&netGuid, NULL); 2511 2382 if (hDeviceInfo == INVALID_HANDLE_VALUE) 2512 2383 SetErrBreak (("SetupDiCreateDeviceInfoList failed (0x%08X)", … … 2514 2385 2515 2386 /* get the class name from GUID */ 2516 ok= SetupDiClassNameFromGuid (&netGuid, className, MAX_PATH, NULL);2517 if (! ok)2387 BOOL fResult = SetupDiClassNameFromGuid (&netGuid, className, MAX_PATH, NULL); 2388 if (!fResult) 2518 2389 SetErrBreak (("SetupDiClassNameFromGuid failed (0x%08X)", 2519 2390 GetLastError())); … … 2521 2392 /* create a device info element and add the new device instance 2522 2393 * key to registry */ 2523 ok= SetupDiCreateDeviceInfo (hDeviceInfo, className, &netGuid, NULL, NULL,2394 fResult = SetupDiCreateDeviceInfo (hDeviceInfo, className, &netGuid, NULL, NULL, 2524 2395 DICD_GENERATE_ID, &DeviceInfoData); 2525 if (! ok)2396 if (!fResult) 2526 2397 SetErrBreak (("SetupDiCreateDeviceInfo failed (0x%08X)", 2527 2398 GetLastError())); … … 2529 2400 /* select the newly created device info to be the currently 2530 2401 selected member */ 2531 ok= SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);2532 if (! ok)2402 fResult = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData); 2403 if (!fResult) 2533 2404 SetErrBreak (("SetupDiSetSelectedDevice failed (0x%08X)", 2534 2405 GetLastError())); … … 2538 2409 /* get the device install parameters and disable filecopy */ 2539 2410 DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS); 2540 ok= SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,2411 fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData, 2541 2412 &DeviceInstallParams); 2542 if ( ok)2413 if (fResult) 2543 2414 { 2544 2415 memset(DeviceInstallParams.DriverPath, 0, sizeof(DeviceInstallParams.DriverPath)); … … 2553 2424 } 2554 2425 2555 ok = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData,2556 2557 if (! ok)2426 fResult = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData, 2427 &DeviceInstallParams); 2428 if (!fResult) 2558 2429 { 2559 2430 DWORD winEr = GetLastError(); 2560 Log("SetupDiSetDeviceInstallParams: SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr); 2561 Assert(0); 2431 LogFlow(("SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr)); 2562 2432 break; 2563 2433 } … … 2565 2435 else 2566 2436 { 2567 Log("SetupDiSetDeviceInstallParams: inf path is too long\n"); 2568 Assert(0); 2437 LogFlow(("SetupDiSetDeviceInstallParams faileed: INF path is too long\n")); 2569 2438 break; 2570 2439 } … … 2573 2442 { 2574 2443 DWORD winEr = GetLastError(); 2575 Assert(0); 2576 Log("VBoxNetCfgWinCreateHostOnlyNetworkInterface: SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr); 2577 } 2578 2444 LogFlow(("SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr)); 2445 } 2579 2446 } 2580 2447 2581 2448 /* build a list of class drivers */ 2582 ok= SetupDiBuildDriverInfoList (hDeviceInfo, &DeviceInfoData,2583 SPDIT_CLASSDRIVER);2584 if (! ok)2449 fResult = SetupDiBuildDriverInfoList (hDeviceInfo, &DeviceInfoData, 2450 SPDIT_CLASSDRIVER); 2451 if (!fResult) 2585 2452 SetErrBreak (("SetupDiBuildDriverInfoList failed (0x%08X)", 2586 2453 GetLastError())); … … 2647 2514 2648 2515 if (!found) 2649 SetErrBreak (("Could not find Host Interface Networking driver! " 2650 "Please reinstall")); 2516 SetErrBreak(("Could not find Host Interface Networking driver! Please reinstall")); 2651 2517 2652 2518 /* set the loopback driver to be the currently selected */ 2653 ok= SetupDiSetSelectedDriver (hDeviceInfo, &DeviceInfoData,2519 fResult = SetupDiSetSelectedDriver (hDeviceInfo, &DeviceInfoData, 2654 2520 &DriverInfoData); 2655 if (! ok)2656 SetErrBreak 2657 2521 if (!fResult) 2522 SetErrBreak(("SetupDiSetSelectedDriver failed (0x%08X)", 2523 GetLastError())); 2658 2524 2659 2525 /* register the phantom device to prepare for install */ 2660 ok= SetupDiCallClassInstaller (DIF_REGISTERDEVICE, hDeviceInfo,2661 &DeviceInfoData);2662 if (! ok)2526 fResult = SetupDiCallClassInstaller (DIF_REGISTERDEVICE, hDeviceInfo, 2527 &DeviceInfoData); 2528 if (!fResult) 2663 2529 { 2664 2530 DWORD err = GetLastError(); … … 2671 2537 2672 2538 /* ask the installer if we can install the device */ 2673 ok= SetupDiCallClassInstaller (DIF_ALLOW_INSTALL, hDeviceInfo,2674 &DeviceInfoData);2675 if (! ok)2539 fResult = SetupDiCallClassInstaller (DIF_ALLOW_INSTALL, hDeviceInfo, 2540 &DeviceInfoData); 2541 if (!fResult) 2676 2542 { 2677 2543 if (GetLastError() != ERROR_DI_DO_DEFAULT) … … 2683 2549 /* get the device install parameters and disable filecopy */ 2684 2550 DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS); 2685 ok= SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,2686 &DeviceInstallParams);2687 if ( ok)2551 fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData, 2552 &DeviceInstallParams); 2553 if (fResult) 2688 2554 { 2689 2555 pQueueCallbackContext = SetupInitDefaultQueueCallback(NULL); … … 2692 2558 DeviceInstallParams.InstallMsgHandlerContext = pQueueCallbackContext; 2693 2559 DeviceInstallParams.InstallMsgHandler = (PSP_FILE_CALLBACK)vboxNetCfgWinPspFileCallback; 2694 ok= SetupDiSetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,2560 fResult = SetupDiSetDeviceInstallParams (hDeviceInfo, &DeviceInfoData, 2695 2561 &DeviceInstallParams); 2696 if (! ok)2562 if (!fResult) 2697 2563 { 2698 2564 DWORD winEr = GetLastError(); 2699 Assert(0); 2700 Log("SetupDiSetDeviceInstallParams: SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr); 2701 } 2702 Assert(ok); 2565 LogFlow(("SetupDiSetDeviceInstallParams failed, winEr (%d)\n", winEr)); 2566 } 2567 Assert(fResult); 2703 2568 } 2704 2569 else 2705 2570 { 2706 2571 DWORD winEr = GetLastError(); 2707 Assert(0); 2708 Log("VBoxNetCfgWinCreateHostOnlyNetworkInterface: SetupInitDefaultQueueCallback failed, winEr (%d)\n", winEr); 2572 LogFlow(("SetupInitDefaultQueueCallback failed, winEr (%d)\n", winEr)); 2709 2573 } 2710 2574 } … … 2712 2576 { 2713 2577 DWORD winEr = GetLastError(); 2714 Assert(0); 2715 Log("VBoxNetCfgWinCreateHostOnlyNetworkInterface: SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr); 2578 LogFlow(("SetupDiGetDeviceInstallParams failed, winEr (%d)\n", winEr)); 2716 2579 } 2717 2580 2718 2581 /* install the files first */ 2719 ok= SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES, hDeviceInfo,2582 fResult = SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES, hDeviceInfo, 2720 2583 &DeviceInfoData); 2721 if (! ok)2584 if (!fResult) 2722 2585 SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES) failed (0x%08X)", 2723 2586 GetLastError())); 2724 2725 2587 /* get the device install parameters and disable filecopy */ 2726 2588 DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS); 2727 ok= SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,2589 fResult = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData, 2728 2590 &DeviceInstallParams); 2729 if ( ok)2591 if (fResult) 2730 2592 { 2731 2593 DeviceInstallParams.Flags |= DI_NOFILECOPY; 2732 ok = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData,2733 &DeviceInstallParams);2734 if (! ok)2594 fResult = SetupDiSetDeviceInstallParams(hDeviceInfo, &DeviceInfoData, 2595 &DeviceInstallParams); 2596 if (!fResult) 2735 2597 SetErrBreak (("SetupDiSetDeviceInstallParams failed (0x%08X)", 2736 2598 GetLastError())); … … 2740 2602 * Register any device-specific co-installers for this device, 2741 2603 */ 2742 2743 ok = SetupDiCallClassInstaller (DIF_REGISTER_COINSTALLERS, 2744 hDeviceInfo, 2745 &DeviceInfoData); 2746 if (!ok) 2604 fResult = SetupDiCallClassInstaller(DIF_REGISTER_COINSTALLERS, 2605 hDeviceInfo, 2606 &DeviceInfoData); 2607 if (!fResult) 2747 2608 SetErrBreak (("SetupDiCallClassInstaller (DIF_REGISTER_COINSTALLERS) failed (0x%08X)", 2748 2609 GetLastError())); … … 2752 2613 * and then do the real install 2753 2614 */ 2754 ok = SetupDiCallClassInstaller(DIF_INSTALLINTERFACES,2755 hDeviceInfo,2756 &DeviceInfoData);2757 if (! ok)2615 fResult = SetupDiCallClassInstaller(DIF_INSTALLINTERFACES, 2616 hDeviceInfo, 2617 &DeviceInfoData); 2618 if (!fResult) 2758 2619 SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLINTERFACES) failed (0x%08X)", 2759 2620 GetLastError())); 2760 2621 2761 ok = SetupDiCallClassInstaller(DIF_INSTALLDEVICE,2762 hDeviceInfo,2763 &DeviceInfoData);2764 if (! ok)2622 fResult = SetupDiCallClassInstaller(DIF_INSTALLDEVICE, 2623 hDeviceInfo, 2624 &DeviceInfoData); 2625 if (!fResult) 2765 2626 SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICE) failed (0x%08X)", 2766 2627 GetLastError())); 2767 2628 2768 2629 /* Figure out NetCfgInstanceId */ 2769 hkey = SetupDiOpenDevRegKey 2770 2771 2772 2773 2774 2630 hkey = SetupDiOpenDevRegKey(hDeviceInfo, 2631 &DeviceInfoData, 2632 DICS_FLAG_GLOBAL, 2633 0, 2634 DIREG_DRV, 2635 KEY_READ); 2775 2636 if (hkey == INVALID_HANDLE_VALUE) 2776 2637 SetErrBreak (("SetupDiOpenDevRegKey failed (0x%08X)", … … 2785 2646 2786 2647 if (!SetupDiGetDeviceRegistryPropertyW(hDeviceInfo, &DeviceInfoData, 2787 SPDRP_FRIENDLYNAME , /* IN DWORD Property,*/ 2788 NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/ 2789 (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/ 2790 sizeof(DevName), /* IN DWORD PropertyBufferSize,*/ 2791 NULL /*OUT PDWORD RequiredSize OPTIONAL*/ 2792 )) 2648 SPDRP_FRIENDLYNAME , /* IN DWORD Property,*/ 2649 NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/ 2650 (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/ 2651 sizeof(DevName), /* IN DWORD PropertyBufferSize,*/ 2652 NULL /*OUT PDWORD RequiredSize OPTIONAL*/)) 2793 2653 { 2794 2654 int err = GetLastError(); … … 2819 2679 */ 2820 2680 if (pQueueCallbackContext) 2821 {2822 2681 SetupTermDefaultQueueCallback(pQueueCallbackContext); 2823 }2824 2682 2825 2683 if (hDeviceInfo != INVALID_HANDLE_VALUE) … … 2827 2685 /* an error has occurred, but the device is registered, we must remove it */ 2828 2686 if (ret != 0 && registered) 2829 SetupDiCallClassInstaller 2830 2831 found = SetupDiDeleteDeviceInfo 2687 SetupDiCallClassInstaller(DIF_REMOVE, hDeviceInfo, &DeviceInfoData); 2688 2689 found = SetupDiDeleteDeviceInfo(hDeviceInfo, &DeviceInfoData); 2832 2690 2833 2691 /* destroy the driver info list */ 2834 2692 if (destroyList) 2835 SetupDiDestroyDriverInfoList 2836 2693 SetupDiDestroyDriverInfoList(hDeviceInfo, &DeviceInfoData, 2694 SPDIT_CLASSDRIVER); 2837 2695 /* clean up the device info set */ 2838 2696 SetupDiDestroyDeviceInfoList (hDeviceInfo); … … 2845 2703 ULONG cbName = sizeof(ConnectoinName); 2846 2704 2847 HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName (DevName, ConnectoinName, &cbName); 2705 HRESULT hr = VBoxNetCfgWinGenHostonlyConnectionName(DevName, ConnectoinName, &cbName); 2706 if (SUCCEEDED(hr)) 2707 hr = VBoxNetCfgWinRenameConnection(pWCfgGuidString, ConnectoinName); 2708 2709 if (lppszName) 2710 { 2711 *lppszName = ::SysAllocString((const OLECHAR *) DevName); 2712 if (!*lppszName) 2713 { 2714 LogFlow(("SysAllocString failed\n")); 2715 hrc = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); 2716 } 2717 } 2718 2719 if (pGuid) 2720 { 2721 hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid); 2722 if (FAILED(hrc)) 2723 LogFlow(("CLSIDFromString failed, hrc (0x%x)\n", hrc)); 2724 } 2725 2726 INetCfg *pNetCfg = NULL; 2727 LPWSTR lpszApp = NULL; 2728 hr = VBoxNetCfgWinQueryINetCfg(&pNetCfg, TRUE, L"VirtualBox Host-Only Creation", 2729 30 * 1000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec. */ 2730 /* TODO: special handling for 6to4svc.dll ???, i.e. several retrieves */ 2731 &lpszApp); 2848 2732 if (hr == S_OK) 2849 2733 { 2850 hr = VBoxNetCfgWinRenameConnection (pWCfgGuidString, ConnectoinName); 2851 } 2852 2853 if (lppszName) 2854 { 2855 *lppszName = ::SysAllocString ((const OLECHAR *) DevName); 2856 if (!*lppszName) 2857 { 2858 Log("VBoxNetCfgWinCreateHostOnlyNetworkInterface: SysAllocString failed\n"); 2859 Assert(0); 2860 hrc = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); 2861 } 2862 } 2863 2864 if (pGuid) 2865 { 2866 hrc = CLSIDFromString(pWCfgGuidString, (LPCLSID)pGuid); 2867 if (hrc != S_OK) 2868 { 2869 Log("VBoxNetCfgWinCreateHostOnlyNetworkInterface: CLSIDFromString failed, hrc (0x%x)\n", hrc); 2870 Assert(0); 2871 } 2872 } 2873 2874 INetCfg *pNc; 2875 LPWSTR lpszApp = NULL; 2876 2877 hr = VBoxNetCfgWinQueryINetCfg(&pNc, TRUE, L"VirtualBox Host-Only Creation", 2878 30000, /* on Vista we often get 6to4svc.dll holding the lock, wait for 30 sec, */ 2879 /* TODO: special handling for 6to4svc.dll ???, i.e. several retrieves */ 2880 &lpszApp); 2881 Assert(hr == S_OK); 2882 if (hr == S_OK) 2883 { 2884 hr = vboxNetCfgWinEnumNetCfgComponents(pNc, 2885 &GUID_DEVCLASS_NETSERVICE, 2886 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 2887 pGuid); 2888 Assert(hr == S_OK); 2889 2890 hr = vboxNetCfgWinEnumNetCfgComponents(pNc, 2891 &GUID_DEVCLASS_NETTRANS, 2892 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 2893 pGuid); 2894 Assert(hr == S_OK); 2895 2896 hr = vboxNetCfgWinEnumNetCfgComponents(pNc, 2897 &GUID_DEVCLASS_NETCLIENT, 2898 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 2899 pGuid); 2900 Assert(hr == S_OK); 2901 2902 if (hr == S_OK) 2903 { 2904 hr = pNc->Apply(); 2905 Assert(hr == S_OK); 2906 } 2907 2908 VBoxNetCfgWinReleaseINetCfg(pNc, TRUE); 2734 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 2735 &GUID_DEVCLASS_NETSERVICE, 2736 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 2737 pGuid); 2738 if (SUCCEEDED(hr)) 2739 { 2740 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 2741 &GUID_DEVCLASS_NETTRANS, 2742 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 2743 pGuid); 2744 if (SUCCEEDED(hr)) 2745 hr = vboxNetCfgWinEnumNetCfgComponents(pNetCfg, 2746 &GUID_DEVCLASS_NETCLIENT, 2747 vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority, 2748 pGuid); 2749 } 2750 2751 if (SUCCEEDED(hr)) 2752 { 2753 hr = pNetCfg->Apply(); 2754 } 2755 else 2756 LogFlow(("Enumeration failed, hr 0x%x\n", hr)); 2757 VBoxNetCfgWinReleaseINetCfg(pNetCfg, TRUE); 2909 2758 } 2910 2759 else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszApp) 2911 2760 { 2912 Log ("VBoxNetCfgWinCreateHostOnlyNetworkInterface: app %S is holding the lock, failed\n", lpszApp);2761 LogFlow(("Application %ws is holding the lock, failed\n", lpszApp)); 2913 2762 CoTaskMemFree(lpszApp); 2914 2763 } 2915 2764 else 2916 { 2917 Log("VBoxNetCfgWinCreateHostOnlyNetworkInterface: VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr); 2918 } 2919 } 2920 2765 LogFlow(("VBoxNetCfgWinQueryINetCfg failed, hr 0x%x\n", hr)); 2766 } 2921 2767 return hrc; 2922 2768 } 2923 2769 2924 2770 #undef SetErrBreak 2771
Note:
See TracChangeset
for help on using the changeset viewer.