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;
DISPID dispid;
hr = winEx->GetDispID(name.data(), fdexNameEnsure, &dispid);
CComBSTR bname = name.c_str();
hr = winEx->GetDispID(bname, fdexNameEnsure, &dispid);
if (FAILED(hr))
return;

View File

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