- Fix compilation when UNICODE is not defined
CORE-9258 #resolve

svn path=/trunk/; revision=68201
This commit is contained in:
Thomas Faber 2015-06-20 09:22:55 +00:00
parent 9046d69084
commit 0c99435b9a
2 changed files with 48 additions and 40 deletions

View file

@ -350,17 +350,25 @@ public:
HRESULT WINAPI UpdateRegistryFromResource(LPCTSTR lpszRes, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries = NULL) HRESULT WINAPI UpdateRegistryFromResource(LPCTSTR lpszRes, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries = NULL)
{ {
CRegObject registrar; CRegObject registrar;
TCHAR modulePath[MAX_PATH]; WCHAR modulePath[MAX_PATH];
HRESULT hResult; HRESULT hResult;
PCWSTR lpwszRes;
hResult = CommonInitRegistrar(registrar, modulePath, sizeof(modulePath) / sizeof(modulePath[0]), pMapEntries); hResult = CommonInitRegistrar(registrar, modulePath, sizeof(modulePath) / sizeof(modulePath[0]), pMapEntries);
if (FAILED(hResult)) if (FAILED(hResult))
return hResult; return hResult;
#ifdef UNICODE
lpwszRes = lpszRes;
#else
/* FIXME: this is a bit of a hack, need to re-evaluate */
WCHAR resid[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, lpszRes, -1, resid, MAX_PATH);
lpwszRes = resid;
#endif
if (bRegister != FALSE) if (bRegister != FALSE)
hResult = registrar.ResourceRegisterSz(modulePath, lpszRes, _T("REGISTRY")); hResult = registrar.ResourceRegisterSz(modulePath, lpwszRes, L"REGISTRY");
else else
hResult = registrar.ResourceUnregisterSz(modulePath, lpszRes, _T("REGISTRY")); hResult = registrar.ResourceUnregisterSz(modulePath, lpwszRes, L"REGISTRY");
return hResult; return hResult;
} }
@ -368,7 +376,7 @@ public:
HRESULT WINAPI UpdateRegistryFromResource(UINT nResID, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries = NULL) HRESULT WINAPI UpdateRegistryFromResource(UINT nResID, BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries = NULL)
{ {
CRegObject registrar; CRegObject registrar;
TCHAR modulePath[MAX_PATH]; WCHAR modulePath[MAX_PATH];
HRESULT hResult; HRESULT hResult;
hResult = CommonInitRegistrar(registrar, modulePath, sizeof(modulePath) / sizeof(modulePath[0]), pMapEntries); hResult = CommonInitRegistrar(registrar, modulePath, sizeof(modulePath) / sizeof(modulePath[0]), pMapEntries);
@ -376,22 +384,22 @@ public:
return hResult; return hResult;
if (bRegister != FALSE) if (bRegister != FALSE)
hResult = registrar.ResourceRegister(modulePath, nResID, _T("REGISTRY")); hResult = registrar.ResourceRegister(modulePath, nResID, L"REGISTRY");
else else
hResult = registrar.ResourceUnregister(modulePath, nResID, _T("REGISTRY")); hResult = registrar.ResourceUnregister(modulePath, nResID, L"REGISTRY");
return hResult; return hResult;
} }
private: private:
HRESULT CommonInitRegistrar(CRegObject &registrar, TCHAR *modulePath, DWORD modulePathCount, struct _ATL_REGMAP_ENTRY *pMapEntries) HRESULT CommonInitRegistrar(CRegObject &registrar, WCHAR *modulePath, DWORD modulePathCount, struct _ATL_REGMAP_ENTRY *pMapEntries)
{ {
HINSTANCE hInstance; HINSTANCE hInstance;
DWORD dwFLen; DWORD dwFLen;
HRESULT hResult; HRESULT hResult;
hInstance = _AtlBaseModule.GetModuleInstance(); hInstance = _AtlBaseModule.GetModuleInstance();
dwFLen = GetModuleFileName(hInstance, modulePath, modulePathCount); dwFLen = GetModuleFileNameW(hInstance, modulePath, modulePathCount);
if (dwFLen == modulePathCount) if (dwFLen == modulePathCount)
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
else if (dwFLen == 0) else if (dwFLen == 0)
@ -413,11 +421,11 @@ private:
if (FAILED(hResult)) if (FAILED(hResult))
return hResult; return hResult;
hResult = registrar.AddReplacement(_T("Module"), modulePath); hResult = registrar.AddReplacement(L"Module", modulePath);
if (FAILED(hResult)) if (FAILED(hResult))
return hResult; return hResult;
hResult = registrar.AddReplacement(_T("Module_Raw"), modulePath); hResult = registrar.AddReplacement(L"Module_Raw", modulePath);
if (FAILED(hResult)) if (FAILED(hResult))
return hResult; return hResult;

View file

@ -194,7 +194,7 @@ protected:
} }
private: private:
inline LONG RegDeleteTreeX(HKEY parentKey, LPCTSTR subKeyName) inline LONG RegDeleteTreeX(HKEY parentKey, LPCWSTR subKeyName)
{ {
wchar_t szBuffer[256]; wchar_t szBuffer[256];
DWORD dwSize; DWORD dwSize;
@ -203,7 +203,7 @@ private:
LONG lRes; LONG lRes;
ATLASSERT(parentKey != NULL); ATLASSERT(parentKey != NULL);
lRes = RegOpenKeyEx(parentKey, subKeyName, 0, KEY_READ | KEY_WRITE, &childKey); lRes = RegOpenKeyExW(parentKey, subKeyName, 0, KEY_READ | KEY_WRITE, &childKey);
if (lRes != ERROR_SUCCESS) if (lRes != ERROR_SUCCESS)
return lRes; return lRes;
@ -216,7 +216,7 @@ private:
dwSize = sizeof(szBuffer) / sizeof(szBuffer[0]); dwSize = sizeof(szBuffer) / sizeof(szBuffer[0]);
} }
RegCloseKey(childKey); RegCloseKey(childKey);
return RegDeleteKey(parentKey, subKeyName); return RegDeleteKeyW(parentKey, subKeyName);
} }
HRESULT strbuf_init(strbuf *buf) HRESULT strbuf_init(strbuf *buf)
@ -387,7 +387,7 @@ private:
if (iter == iter2) if (iter == iter2)
{ {
hResult = strbuf_write(_T("%"), buf, 1); hResult = strbuf_write(L"%", buf, 1);
if (FAILED(hResult)) if (FAILED(hResult))
return hResult; return hResult;
} }
@ -499,10 +499,10 @@ private:
DO_DELETE DO_DELETE
} key_type = NORMAL; } key_type = NORMAL;
static const wchar_t *wstrNoRemove = _T("NoRemove"); static const wchar_t *wstrNoRemove = L"NoRemove";
static const wchar_t *wstrForceRemove = _T("ForceRemove"); static const wchar_t *wstrForceRemove = L"ForceRemove";
static const wchar_t *wstrDelete = _T("Delete"); static const wchar_t *wstrDelete = L"Delete";
static const wchar_t *wstrval = _T("val"); static const wchar_t *wstrval = L"val";
iter = *pstr; iter = *pstr;
hkey = NULL; hkey = NULL;
@ -549,7 +549,7 @@ private:
{ {
if (key_type == FORCE_REMOVE) if (key_type == FORCE_REMOVE)
RegDeleteTreeX(parent_key, buf->str); RegDeleteTreeX(parent_key, buf->str);
lres = RegCreateKey(parent_key, buf->str, &hkey); lres = RegCreateKeyW(parent_key, buf->str, &hkey);
if (lres != ERROR_SUCCESS) if (lres != ERROR_SUCCESS)
{ {
hres = HRESULT_FROM_WIN32(lres); hres = HRESULT_FROM_WIN32(lres);
@ -562,7 +562,7 @@ private:
hres = strbuf_write(buf->str, &name, -1); hres = strbuf_write(buf->str, &name, -1);
if (FAILED(hres)) if (FAILED(hres))
return hres; return hres;
lres = RegOpenKey(parent_key, buf->str, &hkey); lres = RegOpenKeyW(parent_key, buf->str, &hkey);
if (lres != ERROR_SUCCESS) if (lres != ERROR_SUCCESS)
{ {
} }
@ -587,7 +587,7 @@ private:
hres = get_word(&iter, buf); hres = get_word(&iter, buf);
if (FAILED(hres)) if (FAILED(hres))
break; break;
lres = RegSetValueEx(hkey, name.len ? name.str : NULL, 0, REG_SZ, (PBYTE)buf->str, lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_SZ, (PBYTE)buf->str,
(lstrlenW(buf->str) + 1) * sizeof(WCHAR)); (lstrlenW(buf->str) + 1) * sizeof(WCHAR));
if (lres != ERROR_SUCCESS) if (lres != ERROR_SUCCESS)
hres = HRESULT_FROM_WIN32(lres); hres = HRESULT_FROM_WIN32(lres);
@ -596,7 +596,7 @@ private:
hres = get_word(&iter, buf); hres = get_word(&iter, buf);
if (FAILED(hres)) if (FAILED(hres))
break; break;
lres = RegSetValueEx(hkey, name.len ? name.str : NULL, 0, REG_EXPAND_SZ, (PBYTE)buf->str, lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_EXPAND_SZ, (PBYTE)buf->str,
(lstrlenW(buf->str) + 1) * sizeof(WCHAR)); (lstrlenW(buf->str) + 1) * sizeof(WCHAR));
if (lres != ERROR_SUCCESS) if (lres != ERROR_SUCCESS)
hres = HRESULT_FROM_WIN32(lres); hres = HRESULT_FROM_WIN32(lres);
@ -612,7 +612,7 @@ private:
dw = wcstoul(&buf->str[2], &end, 16); dw = wcstoul(&buf->str[2], &end, 16);
else else
dw = wcstol(&buf->str[0], &end, 10); dw = wcstol(&buf->str[0], &end, 10);
lres = RegSetValueEx(hkey, name.len ? name.str : NULL, 0, REG_DWORD, (PBYTE)&dw, sizeof(dw)); lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_DWORD, (PBYTE)&dw, sizeof(dw));
if (lres != ERROR_SUCCESS) if (lres != ERROR_SUCCESS)
hres = HRESULT_FROM_WIN32(lres); hres = HRESULT_FROM_WIN32(lres);
break; break;
@ -631,7 +631,7 @@ private:
count = count / 2; count = count / 2;
for (curIndex = 0; curIndex < count; curIndex++) for (curIndex = 0; curIndex < count; curIndex++)
((BYTE*)buf->str)[curIndex] = (HexToBin(buf->str[curIndex * 2]) << 4) | HexToBin(buf->str[curIndex * 2 + 1]); ((BYTE*)buf->str)[curIndex] = (HexToBin(buf->str[curIndex * 2]) << 4) | HexToBin(buf->str[curIndex * 2 + 1]);
lres = RegSetValueEx(hkey, name.len ? name.str : NULL, 0, REG_BINARY, (PBYTE)buf->str, count); lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_BINARY, (PBYTE)buf->str, count);
if (lres != ERROR_SUCCESS) if (lres != ERROR_SUCCESS)
hres = HRESULT_FROM_WIN32(lres); hres = HRESULT_FROM_WIN32(lres);
break; break;
@ -669,7 +669,7 @@ private:
if (!do_register && (key_type == NORMAL || key_type == FORCE_REMOVE)) if (!do_register && (key_type == NORMAL || key_type == FORCE_REMOVE))
{ {
RegDeleteKey(parent_key, name.str); RegDeleteKeyW(parent_key, name.str);
} }
if (hkey && key_type != IS_VAL) if (hkey && key_type != IS_VAL)
@ -699,20 +699,20 @@ private:
const wchar_t *name; const wchar_t *name;
HKEY key; HKEY key;
} root_keys[] = { } root_keys[] = {
{_T("HKEY_CLASSES_ROOT"), HKEY_CLASSES_ROOT}, {L"HKEY_CLASSES_ROOT", HKEY_CLASSES_ROOT},
{_T("HKEY_CURRENT_USER"), HKEY_CURRENT_USER}, {L"HKEY_CURRENT_USER", HKEY_CURRENT_USER},
{_T("HKEY_LOCAL_MACHINE"), HKEY_LOCAL_MACHINE}, {L"HKEY_LOCAL_MACHINE", HKEY_LOCAL_MACHINE},
{_T("HKEY_USERS"), HKEY_USERS}, {L"HKEY_USERS", HKEY_USERS},
{_T("HKEY_PERFORMANCE_DATA"), HKEY_PERFORMANCE_DATA}, {L"HKEY_PERFORMANCE_DATA", HKEY_PERFORMANCE_DATA},
{_T("HKEY_DYN_DATA"), HKEY_DYN_DATA}, {L"HKEY_DYN_DATA", HKEY_DYN_DATA},
{_T("HKEY_CURRENT_CONFIG"), HKEY_CURRENT_CONFIG}, {L"HKEY_CURRENT_CONFIG", HKEY_CURRENT_CONFIG},
{_T("HKCR"), HKEY_CLASSES_ROOT}, {L"HKCR", HKEY_CLASSES_ROOT},
{_T("HKCU"), HKEY_CURRENT_USER}, {L"HKCU", HKEY_CURRENT_USER},
{_T("HKLM"), HKEY_LOCAL_MACHINE}, {L"HKLM", HKEY_LOCAL_MACHINE},
{_T("HKU"), HKEY_USERS}, {L"HKU", HKEY_USERS},
{_T("HKPD"), HKEY_PERFORMANCE_DATA}, {L"HKPD", HKEY_PERFORMANCE_DATA},
{_T("HKDD"), HKEY_DYN_DATA}, {L"HKDD", HKEY_DYN_DATA},
{_T("HKCC"), HKEY_CURRENT_CONFIG}, {L"HKCC", HKEY_CURRENT_CONFIG},
}; };
iter = data; iter = data;