Changeset 46895 in vbox for trunk/src/VBox/Additions/common/VBoxControl
- Timestamp:
- Jul 2, 2013 8:03:03 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 86883
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp
r46625 r46895 610 610 } 611 611 612 HKEY getVideoKey(bool writable) 612 static int checkVBoxVideoKey(HKEY hkeyVideo) 613 { 614 char szValue[128]; 615 DWORD len = sizeof(szValue); 616 DWORD dwKeyType; 617 LONG status = RegQueryValueExA(hkeyVideo, "Device Description", NULL, &dwKeyType, 618 (LPBYTE)szValue, &len); 619 620 if (status == ERROR_SUCCESS) 621 { 622 /* WDDM has additional chars after "Adapter" */ 623 static char sszDeviceDescription[] = "VirtualBox Graphics Adapter"; 624 if (_strnicmp(szValue, sszDeviceDescription, sizeof(sszDeviceDescription) - sizeof(char)) == 0) 625 { 626 return VINF_SUCCESS; 627 } 628 } 629 630 return VERR_NOT_FOUND; 631 } 632 633 static HKEY getVideoKey(bool writable) 613 634 { 614 635 HKEY hkeyDeviceMap = 0; 615 HKEY hkeyVideo = 0; 616 LONG status; 617 618 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\VIDEO", 0, KEY_READ, &hkeyDeviceMap); 619 if ((status != ERROR_SUCCESS) || !hkeyDeviceMap) 636 LONG status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\VIDEO", 0, KEY_READ, &hkeyDeviceMap); 637 if (status != ERROR_SUCCESS || !hkeyDeviceMap) 620 638 { 621 639 VBoxControlError("Error opening video device map registry key!\n"); 622 640 return 0; 623 641 } 624 char szVideoLocation[256]; 642 643 HKEY hkeyVideo = 0; 644 ULONG iDevice; 625 645 DWORD dwKeyType; 626 szVideoLocation[0] = 0; 627 DWORD len = sizeof(szVideoLocation); 628 status = RegQueryValueExA(hkeyDeviceMap, "\\Device\\Video0", NULL, &dwKeyType, (LPBYTE)szVideoLocation, &len); 646 629 647 /* 630 * This value will start with a weird value: \REGISTRY\Machine 631 * Make sure this is true. 632 */ 633 if ( (status == ERROR_SUCCESS) 634 && (dwKeyType == REG_SZ) 635 && (_strnicmp(szVideoLocation, "\\REGISTRY\\Machine", 17) == 0)) 636 { 637 /* open that branch */ 638 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, &szVideoLocation[18], 0, KEY_READ | (writable ? KEY_WRITE : 0), &hkeyVideo); 648 * Scan all '\Device\VideoX' REG_SZ keys to find VBox video driver entry. 649 * 'ObjectNumberList' REG_BINARY is an array of 32 bit device indexes (X). 650 */ 651 652 /* Get the 'ObjectNumberList' */ 653 ULONG numDevices = 0; 654 DWORD adwObjectNumberList[256]; 655 DWORD len = sizeof(adwObjectNumberList); 656 status = RegQueryValueExA(hkeyDeviceMap, "ObjectNumberList", NULL, &dwKeyType, (LPBYTE)&adwObjectNumberList[0], &len); 657 658 if ( status == ERROR_SUCCESS 659 && dwKeyType == REG_BINARY) 660 { 661 numDevices = len / sizeof(DWORD); 639 662 } 640 663 else 641 664 { 642 VBoxControlError("Error opening registry key '%s'\n", &szVideoLocation[18]); 643 } 665 /* The list might not exists. Use 'MaxObjectNumber' REG_DWORD and build a list. */ 666 DWORD dwMaxObjectNumber = 0; 667 len = sizeof(dwMaxObjectNumber); 668 status = RegQueryValueExA(hkeyDeviceMap, "MaxObjectNumber", NULL, &dwKeyType, (LPBYTE)&dwMaxObjectNumber, &len); 669 670 if ( status == ERROR_SUCCESS 671 && dwKeyType == REG_DWORD) 672 { 673 /* 'MaxObjectNumber' is inclusive. */ 674 numDevices = RT_MIN(dwMaxObjectNumber + 1, RT_ELEMENTS(adwObjectNumberList)); 675 for (iDevice = 0; iDevice < numDevices; iDevice++) 676 { 677 adwObjectNumberList[iDevice] = iDevice; 678 } 679 } 680 } 681 682 if (numDevices == 0) 683 { 684 /* Always try '\Device\Video0' as the old code did. Enum can be used in this case in principle. */ 685 adwObjectNumberList[0] = 0; 686 numDevices = 1; 687 } 688 689 /* Scan device entries */ 690 for (iDevice = 0; iDevice < numDevices; iDevice++) 691 { 692 char szValueName[64]; 693 RTStrPrintf(szValueName, sizeof(szValueName), "\\Device\\Video%u", adwObjectNumberList[iDevice]); 694 695 char szVideoLocation[256]; 696 len = sizeof(szVideoLocation); 697 status = RegQueryValueExA(hkeyDeviceMap, szValueName, NULL, &dwKeyType, (LPBYTE)&szVideoLocation[0], &len); 698 699 /* This value starts with '\REGISTRY\Machine' */ 700 if ( status == ERROR_SUCCESS 701 && dwKeyType == REG_SZ 702 && _strnicmp(szVideoLocation, "\\REGISTRY\\Machine", 17) == 0) 703 { 704 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, &szVideoLocation[18], 0, 705 KEY_READ | (writable ? KEY_WRITE : 0), &hkeyVideo); 706 if (status == ERROR_SUCCESS) 707 { 708 int rc = checkVBoxVideoKey(hkeyVideo); 709 if (RT_SUCCESS(rc)) 710 { 711 /* Found, return hkeyVideo to the caller. */ 712 break; 713 } 714 715 RegCloseKey(hkeyVideo); 716 hkeyVideo = 0; 717 } 718 } 719 } 720 721 if (hkeyVideo == 0) 722 { 723 VBoxControlError("Error opening video registry key!\n"); 724 } 725 644 726 RegCloseKey(hkeyDeviceMap); 645 727 return hkeyVideo;
Note:
See TracChangeset
for help on using the changeset viewer.