|
47 | 47 | #include "GlogUtils.h" |
48 | 48 | #include "SaUtils.h" |
49 | 49 | #include "utils.h" |
| 50 | +#include "TypeLibHelper.h" |
50 | 51 |
|
51 | 52 | #include "rapidassist/errors.h" |
52 | 53 |
|
@@ -133,6 +134,35 @@ STDAPI DllUnregisterServer(void) |
133 | 134 | // unregisters object, typelib and all interfaces in typelib |
134 | 135 | HRESULT hr = _AtlModule.DllUnregisterServer(); |
135 | 136 |
|
| 137 | + // Issue #148 - Can't uninstall |
| 138 | + if ( hr == TYPE_E_REGISTRYACCESS ) |
| 139 | + { |
| 140 | + // Unregistration has failed with error 0x8002801c. |
| 141 | + // Function _AtlModule.DllUnregisterServer() can also return TYPE_E_REGISTRYACCESS if the TypeLib is not registered on system. |
| 142 | + // For example, calling `_AtlModule.DllUnregisterServer()` twice, the second call will return TYPE_E_REGISTRYACCESS. |
| 143 | + // See issue #148 for details. |
| 144 | + // Is this failure because the TypeLib is not registered? |
| 145 | + |
| 146 | + // Get typelib attributes |
| 147 | + TLIBATTR sTLibAttr; |
| 148 | + ZeroMemory(&sTLibAttr, sizeof(TLIBATTR)); |
| 149 | + if (FAILED(GetTypeLibAttribute(_AtlComModule.m_hInstTypeLib, 0, &sTLibAttr))) |
| 150 | + return hr; // return original error |
| 151 | + |
| 152 | + // Silence the original error only if the TypeLib is not registered on system. |
| 153 | + HRESULT hr2 = IsTypeLibRegisteredOnSystem(&sTLibAttr); |
| 154 | + if (SUCCEEDED(hr2) && hr2 == S_FALSE) |
| 155 | + { |
| 156 | + // We could assume the error is because the typelib is not registered. |
| 157 | + // To be certain, we should register the typelib and retry the unregistration: |
| 158 | + // _AtlModule.DllRegisterServer(); // don't care about the actual result |
| 159 | + // hr = _AtlModule.DllUnregisterServer(); |
| 160 | + // but that could mess up the system if another software is listening for new typelib registrations events. |
| 161 | + // So we just overrides the original result. |
| 162 | + return S_OK; |
| 163 | + } |
| 164 | + } |
| 165 | + |
136 | 166 | if (SUCCEEDED(hr)) |
137 | 167 | { |
138 | 168 | // Notify the Shell to pick the changes: |
|
0 commit comments