| 689 | } |
| 690 | |
| 691 | USHORT DecrementSharedCount(const TEXT* filename, bool sw_force, err_handler_t err_handler) |
| 692 | { |
| 693 | /************************************** |
| 694 | * |
| 695 | * D e c r e m e n t S h a r e d C o u n t |
| 696 | * |
| 697 | ************************************** |
| 698 | * |
| 699 | * Functional description |
| 700 | * Decrements the registry Shared Count of a module whose full path & file |
| 701 | * name is given in parameter 'filename'. Typically used to decrement the |
| 702 | * shared count of the GDS32.DLL prior to its eventual removal from WinSysDir. |
| 703 | * Can be used for just about any other shared component. |
| 704 | * User has to have enough rights to write to the HKLM key tree. |
| 705 | * If the shared count reaches zero (or was already zero), the shared count |
| 706 | * value is removed and FB_INSTALL_SHARED_COUNT_ZERO is returned. |
| 707 | * If the sw_force is set, the shared count value is removed and |
| 708 | * FB_INSTALL_SHARED_COUNT_ZERO returned too). |
| 709 | * FB_SUCCESS is returned when the count was decremented without reaching |
| 710 | * zero. FB_FAILURE is returned only in cases of registry access failures. |
| 711 | * |
| 712 | **************************************/ |
| 713 | |
| 714 | HKEY hkey; |
| 715 | DWORD disp; |
| 716 | LONG status = RegCreateKeyEx(HKEY_LOCAL_MACHINE, SHARED_KEY, |
| 717 | 0, "", REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &hkey, &disp); |
| 718 | if (status != ERROR_SUCCESS) |
| 719 | return (*err_handler) (status, "RegCreateKeyEx"); |
| 720 | |
| 721 | LONG count = 0; |
| 722 | if (! sw_force) |
| 723 | { |
| 724 | DWORD type; |
| 725 | DWORD size = sizeof(count); |
| 726 | RegQueryValueEx(hkey, filename, NULL, &type, |
| 727 | reinterpret_cast<BYTE*>(&count), &size); |
| 728 | |
| 729 | --count; |
| 730 | } |
| 731 | |
| 732 | if (count > 0) |
| 733 | { |
| 734 | status = RegSetValueEx(hkey, filename, 0, REG_DWORD, |
| 735 | reinterpret_cast<BYTE*>(&count), sizeof(DWORD)); |
| 736 | if (status != ERROR_SUCCESS) |
| 737 | { |
| 738 | RegCloseKey(hkey); |
| 739 | return (*err_handler) (status, "RegSetValueEx"); |
| 740 | } |
| 741 | RegCloseKey(hkey); |
| 742 | return FB_SUCCESS; |
| 743 | } |
| 744 | |
| 745 | status = RegDeleteValue(hkey, filename); |
| 746 | if (status != ERROR_SUCCESS) |
| 747 | { |
| 748 | RegCloseKey(hkey); |