Author: gedmurphy
Date: Sun May 15 14:40:53 2011
New Revision: 51763
URL:
http://svn.reactos.org/svn/reactos?rev=51763&view=rev
Log:
[ATL]
- Add DECLARE_NO_REGISTRY
- Fix invalid pointer use and add an overloaded assignment operator in
CComDynamicUnkArray
- Add UpdateWindow to the CWindow class
- Add missing error checks
Changes by Andrew Hill <ash77 at reactos dot org>
Modified:
trunk/reactos/lib/atl/atlcom.h
trunk/reactos/lib/atl/atlwin.h
trunk/reactos/lib/atl/statreg.h
Modified: trunk/reactos/lib/atl/atlcom.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/atl/atlcom.h?rev=51763…
==============================================================================
--- trunk/reactos/lib/atl/atlcom.h [iso-8859-1] (original)
+++ trunk/reactos/lib/atl/atlcom.h [iso-8859-1] Sun May 15 14:40:53 2011
@@ -369,10 +369,16 @@
reinterpret_cast<DWORD>(&_CComChainData<classname,
_ComMapClass>::data), \
_Chain},
-#define DECLARE_REGISTRY_RESOURCEID(x)\
- static HRESULT WINAPI UpdateRegistry(BOOL bRegister)\
- {\
- return ATL::_pAtlModule->UpdateRegistryFromResource(x, bRegister); \
+#define DECLARE_NO_REGISTRY()\
+ static HRESULT WINAPI UpdateRegistry(BOOL /*bRegister*/) \
+ { \
+ return S_OK; \
+ }
+
+#define DECLARE_REGISTRY_RESOURCEID(x) \
+ static HRESULT WINAPI UpdateRegistry(BOOL bRegister) \
+ { \
+ return ATL::_pAtlModule->UpdateRegistryFromResource(x, bRegister); \
}
#define DECLARE_NOT_AGGREGATABLE(x) \
@@ -841,8 +847,8 @@
newArray = reinterpret_cast<IUnknown **>(realloc(m_ppUnk, newSize *
sizeof(IUnknown *)));
if (newArray == NULL)
return 0;
+ m_ppUnk = newArray;
memset(&m_ppUnk[m_nSize], 0, (newSize - m_nSize) * sizeof(IUnknown *));
- m_ppUnk = newArray;
m_nSize = newSize;
m_ppUnk[m_nSize] = pUnk;
return m_nSize + 1;
@@ -862,6 +868,15 @@
return FALSE;
}
+private:
+ CComDynamicUnkArray &operator = (const CComDynamicUnkArray &)
+ {
+ return *this;
+ }
+
+ CComDynamicUnkArray(const CComDynamicUnkArray &)
+ {
+ }
};
struct _ATL_CONNMAP_ENTRY
Modified: trunk/reactos/lib/atl/atlwin.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/atl/atlwin.h?rev=51763…
==============================================================================
--- trunk/reactos/lib/atl/atlwin.h [iso-8859-1] (original)
+++ trunk/reactos/lib/atl/atlwin.h [iso-8859-1] Sun May 15 14:40:53 2011
@@ -24,7 +24,7 @@
#define GCCU(x) x __attribute__((unused))
#define Unused(x)
#else
-#define GCCU(x) x
+#define GCCU(x)
#define Unused(x) (x);
#endif // __GNUC__
@@ -353,6 +353,11 @@
return ::ShowWindow(m_hWnd, nCmdShow);
}
+ BOOL UpdateWindow()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::UpdateWindow(m_hWnd);
+ }
};
_declspec(selectany) RECT CWindow::rcDefault = { CW_USEDEFAULT, CW_USEDEFAULT, 0, 0 };
@@ -770,6 +775,8 @@
ATOM Register(WNDPROC *p)
{
+ if (m_wc.hInstance == NULL)
+ m_wc.hInstance = _AtlBaseModule.GetModuleInstance();
if (m_atom == 0)
m_atom = RegisterClassEx(&m_wc);
return m_atom;
Modified: trunk/reactos/lib/atl/statreg.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/atl/statreg.h?rev=5176…
==============================================================================
--- trunk/reactos/lib/atl/statreg.h [iso-8859-1] (original)
+++ trunk/reactos/lib/atl/statreg.h [iso-8859-1] Sun May 15 14:40:53 2011
@@ -89,13 +89,26 @@
rep_list *new_rep;
new_rep = reinterpret_cast<rep_list *>(HeapAlloc(GetProcessHeap(), 0,
sizeof(rep_list)));
+ if (new_rep == NULL)
+ return E_OUTOFMEMORY;
new_rep->key_len = lstrlenW(key);
new_rep->key = reinterpret_cast<OLECHAR *>(HeapAlloc(GetProcessHeap(), 0,
(new_rep->key_len + 1) * sizeof(OLECHAR)));
+ if (new_rep->key == NULL)
+ {
+ HeapFree(GetProcessHeap(), 0, new_rep);
+ return E_OUTOFMEMORY;
+ }
memcpy(new_rep->key, key, (new_rep->key_len + 1) * sizeof(OLECHAR));
len = lstrlenW(item) + 1;
new_rep->item = reinterpret_cast<OLECHAR *>(HeapAlloc(GetProcessHeap(), 0, len
* sizeof(OLECHAR)));
+ if (new_rep->item == NULL)
+ {
+ HeapFree(GetProcessHeap(), 0, new_rep->key);
+ HeapFree(GetProcessHeap(), 0, new_rep);
+ return E_OUTOFMEMORY;
+ }
memcpy(new_rep->item, item, len * sizeof(OLECHAR));
new_rep->next = m_rep;
@@ -205,25 +218,34 @@
return RegDeleteKey(parentKey, subKeyName);
}
- void strbuf_init(strbuf *buf)
+ HRESULT strbuf_init(strbuf *buf)
{
buf->str = reinterpret_cast<LPOLESTR>(HeapAlloc(GetProcessHeap(), 0, 128 *
sizeof(WCHAR)));
+ if (buf->str == NULL)
+ return E_OUTOFMEMORY;
buf->alloc = 128;
buf->len = 0;
- }
-
- void strbuf_write(LPCOLESTR str, strbuf *buf, int len)
- {
+ return S_OK;
+ }
+
+ HRESULT strbuf_write(LPCOLESTR str, strbuf *buf, int len)
+ {
+ LPOLESTR newBuffer;
+
if (len == -1)
len = lstrlenW(str);
- if (buf->len+len+1 >= buf->alloc)
+ if (buf->len + len + 1 >= buf->alloc)
{
buf->alloc = (buf->len + len) * 2;
- buf->str = reinterpret_cast<LPOLESTR>(HeapReAlloc(GetProcessHeap(), 0,
buf->str, buf->alloc * sizeof(WCHAR)));
+ newBuffer = reinterpret_cast<LPOLESTR>(HeapReAlloc(GetProcessHeap(), 0,
buf->str, buf->alloc * sizeof(WCHAR)));
+ if (newBuffer == NULL)
+ return E_OUTOFMEMORY;
+ buf->str = newBuffer;
}
memcpy(buf->str + buf->len, str, len * sizeof(OLECHAR));
buf->len += len;
buf->str[buf->len] = '\0';
+ return S_OK;
}
@@ -242,11 +264,18 @@
{
filelen = GetFileSize(file, NULL);
regstra = reinterpret_cast<LPSTR>(HeapAlloc(GetProcessHeap(), 0, filelen));
+ if (regstra == NULL)
+ return E_OUTOFMEMORY;
lres = ReadFile(file, regstra, filelen, NULL, NULL);
if (lres == ERROR_SUCCESS)
{
len = MultiByteToWideChar(CP_ACP, 0, regstra, filelen, NULL, 0) + 1;
regstrw = reinterpret_cast<LPWSTR>(HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, len * sizeof(WCHAR)));
+ if (regstra == NULL)
+ {
+ HeapFree(GetProcessHeap(), 0, regstra);
+ return E_OUTOFMEMORY;
+ }
MultiByteToWideChar(CP_ACP, 0, regstra, filelen, regstrw, len);
regstrw[len - 1] = '\0';
@@ -291,6 +320,8 @@
{
len = MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(regstra),
reslen, NULL, 0) + 1;
regstrw = reinterpret_cast<LPWSTR>(HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, len * sizeof(WCHAR)));
+ if (regstrw == NULL)
+ return E_OUTOFMEMORY;
MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(regstra), reslen,
regstrw, len);
regstrw[len - 1] = '\0';
@@ -316,7 +347,9 @@
strbuf buf;
HRESULT hResult;
- strbuf_init(&buf);
+ hResult = strbuf_init(&buf);
+ if (FAILED(hResult))
+ return hResult;
hResult = do_preprocess(data, &buf);
if (SUCCEEDED(hResult))
{
@@ -334,12 +367,15 @@
LPCOLESTR iter;
LPCOLESTR iter2;
rep_list *rep_iter;
+ HRESULT hResult;
iter2 = data;
iter = wcschr(data, '%');
while (iter)
{
- strbuf_write(iter2, buf, static_cast<int>(iter - iter2));
+ hResult = strbuf_write(iter2, buf, static_cast<int>(iter - iter2));
+ if (FAILED(hResult))
+ return hResult;
iter2 = ++iter;
if (!*iter2)
@@ -349,7 +385,11 @@
return DISP_E_EXCEPTION;
if (iter == iter2)
- strbuf_write(_T("%"), buf, 1);
+ {
+ hResult = strbuf_write(_T("%"), buf, 1);
+ if (FAILED(hResult))
+ return hResult;
+ }
else
{
for (rep_iter = m_rep; rep_iter; rep_iter = rep_iter->next)
@@ -360,14 +400,18 @@
if (!rep_iter)
return DISP_E_EXCEPTION;
- strbuf_write(rep_iter->item, buf, -1);
+ hResult = strbuf_write(rep_iter->item, buf, -1);
+ if (FAILED(hResult))
+ return hResult;
}
iter2 = ++iter;
iter = wcschr(iter, '%');
}
- strbuf_write(iter2, buf, -1);
+ hResult = strbuf_write(iter2, buf, -1);
+ if (FAILED(hResult))
+ return hResult;
return S_OK;
}
@@ -376,6 +420,7 @@
{
LPCOLESTR iter;
LPCOLESTR iter2;
+ HRESULT hResult;
iter2 = *str;
buf->len = 0;
@@ -392,7 +437,9 @@
if (*iter == '}' || *iter == '=')
{
- strbuf_write(iter++, buf, 1);
+ hResult = strbuf_write(iter++, buf, 1);
+ if (FAILED(hResult))
+ return hResult;
}
else if (*iter == '\'')
{
@@ -403,20 +450,36 @@
*str = iter;
return DISP_E_EXCEPTION;
}
- strbuf_write(iter2, buf, static_cast<int>(iter - iter2));
+ hResult = strbuf_write(iter2, buf, static_cast<int>(iter - iter2));
+ if (FAILED(hResult))
+ return hResult;
iter++;
}
else
{
while (*iter && !iswspace(*iter))
iter++;
- strbuf_write(iter2, buf, static_cast<int>(iter - iter2));
+ hResult = strbuf_write(iter2, buf, static_cast<int>(iter - iter2));
+ if (FAILED(hResult))
+ return hResult;
}
while (iswspace(*iter))
iter++;
*str = iter;
return S_OK;
+ }
+
+ inline unsigned int HexToBin(char a)
+ {
+ if (a >= '0' && a <= '9')
+ return a - 0x30;
+ if (a >= 'A' && a <= 'F')
+ return a - 'A' + 10;
+ if (a >= 'a' && a <= 'f')
+ return a - 'a' + 10;
+ ATLASSERT(false);
+ return 0;
}
HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOOL do_register)
@@ -446,7 +509,9 @@
hres = get_word(&iter, buf);
if (FAILED(hres))
return hres;
- strbuf_init(&name);
+ hres = strbuf_init(&name);
+ if (FAILED(hres))
+ return hres;
while(buf->str[1] || buf->str[0] != '}')
{
@@ -463,7 +528,7 @@
if (key_type != NORMAL)
{
hres = get_word(&iter, buf);
- if(FAILED(hres))
+ if (FAILED(hres))
break;
}
@@ -472,7 +537,9 @@
if (key_type == IS_VAL)
{
hkey = parent_key;
- strbuf_write(buf->str, &name, -1);
+ hres = strbuf_write(buf->str, &name, -1);
+ if (FAILED(hres))
+ return hres;
}
else if (key_type == DO_DELETE)
{
@@ -492,7 +559,9 @@
}
else if (key_type != IS_VAL && key_type != DO_DELETE)
{
- strbuf_write(buf->str, &name, -1);
+ hres = strbuf_write(buf->str, &name, -1);
+ if (FAILED(hres))
+ return hres;
lres = RegOpenKey(parent_key, buf->str, &hkey);
if (lres != ERROR_SUCCESS)
{
@@ -521,31 +590,50 @@
lres = RegSetValueEx(hkey, name.len ? name.str : NULL, 0, REG_SZ,
(PBYTE)buf->str,
(lstrlenW(buf->str) + 1) * sizeof(WCHAR));
if (lres != ERROR_SUCCESS)
- {
hres = HRESULT_FROM_WIN32(lres);
+ break;
+ case 'e':
+ hres = get_word(&iter, buf);
+ if (FAILED(hres))
break;
- }
+ lres = RegSetValueEx(hkey, name.len ? name.str : NULL, 0, REG_EXPAND_SZ,
(PBYTE)buf->str,
+ (lstrlenW(buf->str) + 1) * sizeof(WCHAR));
+ if (lres != ERROR_SUCCESS)
+ hres = HRESULT_FROM_WIN32(lres);
break;
case 'd':
{
+ hres = get_word(&iter, buf);
+ if (FAILED(hres))
+ break;
WCHAR *end;
DWORD dw;
- if(*iter == '0' && iter[1] == 'x')
- {
- iter += 2;
- dw = wcstol(iter, &end, 16);
- }
+ if ((buf->str[0] == '0' && buf->str[1] == 'x') ||
(buf->str[0] == '&' && buf->str[1] == 'H'))
+ dw = wcstoul(&buf->str[2], &end, 16);
else
- {
- dw = wcstol(iter, &end, 10);
- }
- iter = end;
+ dw = wcstol(&buf->str[0], &end, 10);
lres = RegSetValueEx(hkey, name.len ? name.str : NULL, 0, REG_DWORD,
(PBYTE)&dw, sizeof(dw));
if (lres != ERROR_SUCCESS)
- {
hres = HRESULT_FROM_WIN32(lres);
+ break;
+ }
+ case 'b':
+ {
+ DWORD count;
+ DWORD curIndex;
+
+ hres = get_word(&iter, buf);
+ if (FAILED(hres))
break;
- }
+ count = buf->len;
+ if ((count & 1) != 0)
+ return DISP_E_EXCEPTION;
+ count = count / 2;
+ for (curIndex = 0; curIndex < count; curIndex++)
+ 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);
+ if (lres != ERROR_SUCCESS)
+ hres = HRESULT_FROM_WIN32(lres);
break;
}
default:
@@ -628,9 +716,10 @@
};
iter = data;
- hResult = S_OK;
-
- strbuf_init(&buf);
+
+ hResult = strbuf_init(&buf);
+ if (FAILED(hResult))
+ return hResult;
hResult = get_word(&iter, &buf);
if (FAILED(hResult))
return hResult;