BOOL CWDBho::GetSource(CString &refString)
{
BOOL bRetVal = FALSE;
CComPtr<IDispatch> spDisp;
HRESULT hr = mWebBrowser2->get_Document(&spDisp);
if (spDisp != NULL)
{
HGLOBAL hMemory;
hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
if (hMemory != NULL)
{
CComQIPtr<IPersistStreamInit> spPersistStream = spDisp;
if (spPersistStream != NULL)
{
CComPtr<IStream> spStream;
if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
{
spPersistStream->Save(spStream, FALSE); LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
if (pstr != NULL)
{
// Stream is always ANSI, but CString
// assignment operator will convert implicitly.
bRetVal = TRUE;
TRY
{
refString = pstr;
}
CATCH_ALL(e)
{
bRetVal = FALSE;
}
END_CATCH_ALL if(bRetVal == FALSE)
GlobalFree(hMemory);
else
GlobalUnlock(hMemory);
}
}
}
}
}
return bRetVal;
}抄到一段代码,发现只能获取到4k的内容,没找到什么地方限制。
{
BOOL bRetVal = FALSE;
CComPtr<IDispatch> spDisp;
HRESULT hr = mWebBrowser2->get_Document(&spDisp);
if (spDisp != NULL)
{
HGLOBAL hMemory;
hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
if (hMemory != NULL)
{
CComQIPtr<IPersistStreamInit> spPersistStream = spDisp;
if (spPersistStream != NULL)
{
CComPtr<IStream> spStream;
if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
{
spPersistStream->Save(spStream, FALSE); LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
if (pstr != NULL)
{
// Stream is always ANSI, but CString
// assignment operator will convert implicitly.
bRetVal = TRUE;
TRY
{
refString = pstr;
}
CATCH_ALL(e)
{
bRetVal = FALSE;
}
END_CATCH_ALL if(bRetVal == FALSE)
GlobalFree(hMemory);
else
GlobalUnlock(hMemory);
}
}
}
}
}
return bRetVal;
}抄到一段代码,发现只能获取到4k的内容,没找到什么地方限制。
改了貌似也不好使。
这里的问题吧,试试
hMemory = GlobalAlloc(GMEM_FIXED, 1024*1024);
hMemoryNULL, TRUE, &spStream)The initial size of the stream is the size of the memory handle returned by the Microsoft Win32 GlobalSize function. Because of rounding, this is not necessarily the same size that was originally allocated for the handle. If the logical size of the stream is important, follow the call to this function with a call to the IStream::SetSize method.
CComPtr<IDispatch> spDisp;
HRESULT hr = mWebBrowser2->get_Document(&spDisp);
CComQIPtr<IPersistStreamInit> spPersistStream = spDisp;
CComPtr<IStream> spStream;
HGLOBAL hMemory;
if (spDisp != NULL)
{
// ULARGE_INTEGER uint;
// DWORD dw=4096*8;
// uint.QuadPart=dw;
// spStream->SetSize(uint);
CreateStreamOnHGlobal(NULL, TRUE, &spStream);
spPersistStream->Save(spStream, FALSE);
GetHGlobalFromStream(spStream, &hMemory);
LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
refString = pstr;
}
代码改成这样,还是只有4k,另外加入setsize就报错。