diff --git a/dlls/mshtml/htmlbody.c b/dlls/mshtml/htmlbody.c
index 981d93f9b41..a49f8162c08 100644
--- a/dlls/mshtml/htmlbody.c
+++ b/dlls/mshtml/htmlbody.c
@@ -407,27 +407,14 @@ static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIA
static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
{
HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
- nsAString strColor;
+ nsAString nsstr;
nsresult nsres;
- HRESULT hres;
TRACE("(%p)->(%p)\n", This, p);
- nsAString_Init(&strColor, NULL);
- nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &strColor);
- if(NS_SUCCEEDED(nsres)) {
- const PRUnichar *color;
-
- nsAString_GetData(&strColor, &color);
- V_VT(p) = VT_BSTR;
- hres = nscolor_to_str(color, &V_BSTR(p));
- }else {
- ERR("SetBgColor failed: %08x\n", nsres);
- hres = E_FAIL;
- }
-
- nsAString_Finish(&strColor);
- return hres;
+ nsAString_Init(&nsstr, NULL);
+ nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &nsstr);
+ return return_nsstr_variant(nsres, &nsstr, NSSTR_COLOR, p);
}
static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 565a2428baa..7b2f927e19e 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -982,6 +982,7 @@ UINT32 nsAString_GetData(const nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;
void nsAString_Finish(nsAString*) DECLSPEC_HIDDEN;
#define NSSTR_IMPLICIT_PX 0x01
+#define NSSTR_COLOR 0x02
HRESULT map_nsresult(nsresult) DECLSPEC_HIDDEN;
HRESULT return_nsstr(nsresult,nsAString*,BSTR*) DECLSPEC_HIDDEN;
diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c
index 2d1eb817dc5..9a23785ca67 100644
--- a/dlls/mshtml/nsembed.c
+++ b/dlls/mshtml/nsembed.c
@@ -964,14 +964,15 @@ HRESULT return_nsstr(nsresult nsres, nsAString *nsstr, BSTR *p)
HRESULT return_nsstr_variant(nsresult nsres, nsAString *nsstr, unsigned flags, VARIANT *p)
{
+ HRESULT hres = S_OK;
+
if(NS_FAILED(nsres)) {
ERR("failed: %08x\n", nsres);
nsAString_Finish(nsstr);
- return E_FAIL;
+ return map_nsresult(nsres);
}
if(NS_StringGetIsVoid(nsstr)) {
- TRACE("ret null\n");
V_VT(p) = VT_NULL;
}else {
const WCHAR *str;
@@ -989,20 +990,23 @@ HRESULT return_nsstr_variant(nsresult nsres, nsAString *nsstr, unsigned flags, V
if(iter == str + len && dot) len = dot - str;
}
}
- TRACE("ret %s\n", debugstr_wn(str, len));
- if(*str) {
+ if(flags & NSSTR_COLOR) {
+ hres = nscolor_to_str(str, &V_BSTR(p));
+ }else if(*str) {
V_BSTR(p) = SysAllocStringLen(str, len);
- if(!V_BSTR(p)) {
- nsAString_Finish(nsstr);
- return E_OUTOFMEMORY;
- }
+ if(!V_BSTR(p))
+ hres = E_OUTOFMEMORY;
}else {
V_BSTR(p) = NULL;
}
- V_VT(p) = VT_BSTR;
+ if(SUCCEEDED(hres))
+ V_VT(p) = VT_BSTR;
}
nsAString_Finish(nsstr);
+ if(FAILED(hres))
+ return hres;
+ TRACE("ret %s\n", debugstr_variant(p));
return S_OK;
}