This commit is contained in:
恍兮惚兮 2024-12-29 17:33:33 +08:00
parent 905fe2b819
commit 45294aaa3d
2 changed files with 9 additions and 15 deletions

View File

@ -1050,7 +1050,8 @@ void AddCustomObject(IHTMLDocument2 *doc, IDispatch *custObj, std::wstring name)
return; return;
DISPID dispid; DISPID dispid;
hr = winEx->GetDispID(name.data(), fdexNameEnsure, &dispid); CComBSTR bname = name.c_str();
hr = winEx->GetDispID(bname, fdexNameEnsure, &dispid);
if (FAILED(hr)) if (FAILED(hr))
return; return;

View File

@ -307,14 +307,11 @@ DECLARE_API void html_eval(void *web, const wchar_t *js)
if (FAILED(pDocument->get_Script(&scriptDispatch))) if (FAILED(pDocument->get_Script(&scriptDispatch)))
return; return;
DISPID dispid; DISPID dispid;
BSTR evalStr = SysAllocString(L"eval"); CComBSTR evalStr = L"eval";
if (scriptDispatch->GetIDsOfNames(IID_NULL, &evalStr, 1, if (scriptDispatch->GetIDsOfNames(IID_NULL, &evalStr, 1,
LOCALE_SYSTEM_DEFAULT, &dispid) != S_OK) LOCALE_SYSTEM_DEFAULT, &dispid) != S_OK)
{
SysFreeString(evalStr);
return; return;
}
SysFreeString(evalStr);
DISPPARAMS params; DISPPARAMS params;
VARIANT arg; VARIANT arg;
@ -330,13 +327,9 @@ DECLARE_API void html_eval(void *web, const wchar_t *js)
int n = wcslen(prologue) + wcslen(epilogue) + wcslen(js) + 1; int n = wcslen(prologue) + wcslen(epilogue) + wcslen(js) + 1;
auto eval = std::make_unique<wchar_t[]>(n); auto eval = std::make_unique<wchar_t[]>(n);
_snwprintf(eval.get(), n, L"%s%s%s", prologue, js, epilogue); _snwprintf(eval.get(), n, L"%s%s%s", prologue, js, epilogue);
arg.bstrVal = SysAllocString(eval.get()); CComBSTR bstrVal = eval.get();
if (scriptDispatch->Invoke( arg.bstrVal = bstrVal;
dispid, IID_NULL, 0, DISPATCH_METHOD, scriptDispatch->Invoke(
&params, &result, &excepInfo, &nArgErr) != S_OK) dispid, IID_NULL, 0, DISPATCH_METHOD,
{ &params, &result, &excepInfo, &nArgErr);
SysFreeString(arg.bstrVal);
return;
}
SysFreeString(arg.bstrVal);
} }