| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // Defines a map for adding variables to rgs files. This allows COM object | |
| 6 // classes to declare the values of these variables so that we don't need to | |
| 7 // copy/paste them and manually keep them in sync. | |
| 8 // To use this, declare the registry ID of your RGS file using | |
| 9 // the DECLARE_REGISTRY_RESOURCEID_EX macro, instead of the | |
| 10 // DECLARE_REGISTRY_RESOURCEID, then add a registry map to your class | |
| 11 // using the registry map macros: | |
| 12 // BEGIN_REGISTRY_MAP(MyClassName) | |
| 13 // REGMAP_ENTRY("NAME", "MyClassName Class") | |
| 14 // REGMAP_ENTRY_UUID("CLSID", CLSID_MyClassName) | |
| 15 // END_REGISTRY_MAP() | |
| 16 // | |
| 17 // You can then refer to the names above in your RGS file as | |
| 18 // variables %NAME% and %CLSID%, respectively. | |
| 19 #ifndef BASE_WIN_RGS_HELPER_H_ | |
| 20 #define BASE_WIN_RGS_HELPER_H_ | |
| 21 | |
| 22 #include "base/string_util.h" | |
| 23 | |
| 24 struct ATLRegmapEntryHelper : public _ATL_REGMAP_ENTRY { | |
| 25 ATLRegmapEntryHelper() { | |
| 26 szKey = NULL; | |
| 27 szData = NULL; | |
| 28 } | |
| 29 ATLRegmapEntryHelper(LPCOLESTR key, LPCOLESTR data) { | |
| 30 szKey = key; | |
| 31 size_t size = lstrlen(data) + 1; | |
| 32 szData = new wchar_t[size]; | |
| 33 base::wcslcpy(const_cast<wchar_t*>(szData), data, size); | |
| 34 } | |
| 35 | |
| 36 ATLRegmapEntryHelper(LPCOLESTR key, UINT resid) { | |
| 37 wchar_t data[256] = {0}; | |
| 38 szKey = key; | |
| 39 if (::LoadString(_pModule->m_hInstResource, resid, data, | |
| 40 arraysize(data) - 1) == 0) { | |
| 41 *data = L'\0'; | |
| 42 } | |
| 43 | |
| 44 size_t size = lstrlen(data) + 1; | |
| 45 | |
| 46 szData = new wchar_t[size]; | |
| 47 base::wcslcpy(const_cast<wchar_t*>(szData), data, size); | |
| 48 } | |
| 49 | |
| 50 ATLRegmapEntryHelper(LPCOLESTR key, REFGUID guid) { | |
| 51 szKey = key; | |
| 52 static const size_t kGuidStringSize = 40; | |
| 53 szData = new wchar_t[kGuidStringSize]; | |
| 54 if (szData) { | |
| 55 if (::StringFromGUID2(guid, const_cast<LPOLESTR>(szData), | |
| 56 kGuidStringSize) == 0) { | |
| 57 *const_cast<LPOLESTR>(szData) = L'\0'; | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 ~ATLRegmapEntryHelper() { | |
| 62 delete [] szData; | |
| 63 } | |
| 64 }; | |
| 65 | |
| 66 #define BEGIN_REGISTRY_MAP(x)\ | |
| 67 static struct _ATL_REGMAP_ENTRY *_GetRegistryMap() {\ | |
| 68 static const ATLRegmapEntryHelper map[] = { | |
| 69 #define REGMAP_ENTRY(x, y) ATLRegmapEntryHelper(OLESTR(##x), OLESTR(##y)), | |
| 70 | |
| 71 #define REGMAP_UUID(x, clsid) ATLRegmapEntryHelper(OLESTR(##x), clsid), | |
| 72 | |
| 73 // This allows usage of a Resource string. | |
| 74 #define REGMAP_RESOURCE(x, resid) ATLRegmapEntryHelper(OLESTR(##x), resid), | |
| 75 | |
| 76 // This allows usage of a static function to be called to provide the string. | |
| 77 #define REGMAP_FUNCTION(x, f) ATLRegmapEntryHelper(OLESTR(##x), ##f()), | |
| 78 | |
| 79 #define END_REGISTRY_MAP() ATLRegmapEntryHelper() };\ | |
| 80 return (_ATL_REGMAP_ENTRY*)map;\ | |
| 81 } | |
| 82 | |
| 83 #define DECLARE_REGISTRY_RESOURCEID_EX(x)\ | |
| 84 static HRESULT WINAPI UpdateRegistry(BOOL bRegister) {\ | |
| 85 return ATL::_pAtlModule->UpdateRegistryFromResource((UINT)x, bRegister, \ | |
| 86 _GetRegistryMap());\ | |
| 87 } | |
| 88 | |
| 89 #endif // BASE_WIN_RGS_HELPER_H_ | |
| OLD | NEW |