我编一个能显示图片链接的小程序,可是遇到了一个很奇怪的问题, 如果那个图片链接事先我有在IE里面打开过,然后再用我的程序来打开能正常显示,
而如果我事先没有在IE里面打开过, 却都显示不出来 这是杂回事???
下面是我代码:
void CTESTJPGDlg::OnButton3()
{
// TODO: Add your control notification handler code here
UpdateData(true);
IStream* pstm=NULL;
CInternetSession session;
CHttpFile *file=NULL;
CString str;
try
{
file=(CHttpFile*)session.OpenURL(m_url);
}
catch(CInternetException *pEx)
{
file=NULL;
pEx->Delete();
MessageBox("....");
return;
}
HRESULT hr;
DWORD dwSize = file->GetLength();
HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );
LPVOID lpBuf = ::GlobalLock( hMem );
file->ReadHuge( lpBuf, dwSize );
::GlobalUnlock( hMem );
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pstm );
ASSERT ( SUCCEEDED(hr) );
if ( OleLoadPicture( pstm, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture ) !=S_OK )
{
MessageBox("p...");
}
Invalidate();
MessageBox("OK...");
}