diff --git a/.gitignore b/.gitignore index 9f94303a..23982ea4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ ignored/*.* *.suo /.vs /.xs -/build \ No newline at end of file +/build* \ No newline at end of file diff --git a/DmMain/inc/Widgets/DUIIE.h b/DmMain/inc/Widgets/DUIIE.h index b97fea7e..88d8b390 100644 --- a/DmMain/inc/Widgets/DUIIE.h +++ b/DmMain/inc/Widgets/DUIIE.h @@ -198,7 +198,7 @@ namespace DM /// @brief 获得当前页面 /// @param[in] pszURL 接收当前url的字符串缓冲区 - /// @param[in] nMaxLen 字符串缓冲区的最大长度 + /// @param[in] nMaxLen 字符串缓冲区的最大长度, 需要为L'\0'预留空间 /// @return HRESULT,失败为S_FALSE HRESULT GetUrl(LPWSTR pszUrl, int nMaxLen); CStringW GetUrl(); @@ -261,7 +261,7 @@ namespace DM /// @param[in] strFun 指定要脚本执行的函数名称 /// @param[in] vecParams 给定要脚本执行的函数的参数列表 /// @param[out] strResult 返回脚本函数执行的结果 - /// @param[in] nMaxLen 返回脚本函数执行的结果缓冲区的最大长度 + /// @param[in] nMaxLen 返回脚本函数执行的结果缓冲区的最大长度, 需要为L'\0'预留空间 /// @return HRESULT,失败为E_FAIL HRESULT ExecuteScriptFuntion( LPCWSTR pszFun, diff --git a/DmMain/src/Widgets/DUIIE.cpp b/DmMain/src/Widgets/DUIIE.cpp index 0bd7adbc..b6cd80d0 100644 --- a/DmMain/src/Widgets/DUIIE.cpp +++ b/DmMain/src/Widgets/DUIIE.cpp @@ -757,23 +757,20 @@ namespace DM { DMComPtr pWeb = Ptr(); if (!pWeb) - { break; - } + BSTR _bsURL = NULL; hr = pWeb->get_LocationURL(&_bsURL); if (!SUCCEEDED(hr) || _bsURL == NULL) break; - CStringA strUrlA =_com_util::ConvertBSTRToString(_bsURL) ; - CStringW strUrlW = DMA2W(strUrlA, CP_UTF8); - if (nMaxLen < strUrlW.GetLength()) - { - break; - } - ZeroMemory(pszUrl, nMaxLen*sizeof(wchar_t)); - memcpy(pszUrl, strUrlW, strUrlW.GetLength()*sizeof(wchar_t)); - hr = S_OK; + UINT cch = ::SysStringLen(_bsURL); + if (nMaxLen > cch) { + memcpy(pszUrl, _bsURL, cch * sizeof(wchar_t)); + pszUrl[cch] = L'\0'; + hr = S_OK; + } + ::SysFreeString(_bsURL); } while (false); return hr; } @@ -785,15 +782,14 @@ namespace DM { DMComPtr pWeb = Ptr(); if (!pWeb) - { break; - } + BSTR _bsURL = NULL; HRESULT hr = pWeb->get_LocationURL(&_bsURL); if (!SUCCEEDED(hr) || _bsURL == NULL) break; - CStringA strUrlA =_com_util::ConvertBSTRToString(_bsURL) ; - strUrl = DMA2W(strUrlA, CP_UTF8); + strUrl.Append(_bsURL, ::SysStringLen(_bsURL)); + ::SysFreeString(_bsURL); } while (false); return strUrl; } @@ -1131,12 +1127,11 @@ namespace DM if (strResult != NULL && _varErr.vt == VT_BSTR) { - CStringA strResultA =_com_util::ConvertBSTRToString(_varErr.bstrVal) ; - CStringW strResultW = DMA2W(strResultA, CP_UTF8); - if (nMaxLen > strResultW.GetLength()) + int cch = ::SysStringLen(_varErr.bstrVal); + if (nMaxLen > cch) { - ZeroMemory(strResult, nMaxLen*sizeof(wchar_t)); - memcpy(strResult, strResultW, strResultW.GetLength()*sizeof(wchar_t)); + memcpy(strResult, _varErr.bstrVal, cch * sizeof(wchar_t)); + strResult[cch] = L'\0'; } } } while (false);