首页上一页 1 下一页尾页 1 条记录 1/1页
vc++典型模块大全 --企业通讯模块发图片功能有问题
发表在C语言图书答疑
2010-08-23
是否精华
是
否
版块置顶:
是
否
vc++典型模块大全 --企业通讯模块发图片功能有问题,发图片不能成功,程序执行到红色的部分就出错了 ,希望能尽快的解决一下,谢谢了 !
下面贴上出错的代码:
BOOL CSendDlg::InsertImage(IRichEditOle *lpRichEditOle,CString &csFileName)
{
IStorage *lpStorage = NULL; //存储接口
IOleObject *lpOleObject = NULL; //OLE object
LPLOCKBYTES lpLockBytes = NULL;
IOleClientSite *lpOleClientSite = NULL;
GIFLib::ICGifPtr lpAnimator;
CLSID clsid;
REOBJECT reobject;
HRESULT hr;
if (lpRichEditOle == NULL)
{
return FALSE;
}
hr = ::CoInitialize(NULL);
if (FAILED(hr))
{
_com_issue_error(hr);
}
//
[font size=4][font color=#FF0000][strong]hr = lpAnimator.CreateInstance(GIFLib::CLSID_CGif)[/strong];[/font]
[/font] if (FAILED(hr))
{
_com_issue_error(hr);
}
lpRichEditOle->GetClientSite(&lpOleClientSite);
try
{
//获取OLE对象接口
hr = lpAnimator->QueryInterface(IID_IOleObject,(void**)&lpOleObject);
if (FAILED(hr))
{
AfxMessageBox("Error QueryInterface");
}
hr = lpOleObject->GetUserClassID(&clsid);
if (FAILED(hr))
{
AfxMessageBox("Error GetUserClassID");
}
//防止出现错误提示
lpOleObject->SetClientSite(NULL);
lpOleObject->SetClientSite(lpOleClientSite);
hr = ::CreateILockBytesOnHGlobal(NULL,TRUE,&lpLockBytes); //创建LOCKBYTE对象
if (FAILED(hr))
{
AfxThrowOleException(hr);
}
ASSERT(lpLockBytes != NULL);
hr = ::StgCreateDocfileOnILockBytes(lpLockBytes,
STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE,
0,&lpStorage);
if (FAILED(hr))
{
VERIFY(lpLockBytes->Release() == 0);
lpLockBytes = NULL;
AfxThrowOleException(hr);
}
ZeroMemory(&reobject,sizeof(REOBJECT)); //初始化一对象
reobject.cbStruct = sizeof(REOBJECT);
reobject.clsid = clsid;
reobject.cp = REO_CP_SELECTION;
reobject.dvaspect = DVASPECT_CONTENT;
reobject.dwFlags = REO_BLANK;
reobject.poleobj = lpOleObject;
reobject.polesite =lpOleClientSite;
reobject.pstg = lpStorage;
hr = lpRichEditOle->InsertObject(&reobject);
hr = lpAnimator->LoadFromFile(csFileName.AllocSysString());
if (FAILED(hr))
{
AfxThrowOleException(hr);
}
RedrawWindow(); //刷新窗体
lpOleClientSite->SaveObject();
OleSetContainedObject(lpOleObject,TRUE);
}
catch (CException* e)
{
e->Delete();
}
lpAnimator->Release();
lpStorage->Release();
return TRUE;
}
。
下面贴上出错的代码:
BOOL CSendDlg::InsertImage(IRichEditOle *lpRichEditOle,CString &csFileName)
{
IStorage *lpStorage = NULL; //存储接口
IOleObject *lpOleObject = NULL; //OLE object
LPLOCKBYTES lpLockBytes = NULL;
IOleClientSite *lpOleClientSite = NULL;
GIFLib::ICGifPtr lpAnimator;
CLSID clsid;
REOBJECT reobject;
HRESULT hr;
if (lpRichEditOle == NULL)
{
return FALSE;
}
hr = ::CoInitialize(NULL);
if (FAILED(hr))
{
_com_issue_error(hr);
}
//
[font size=4][font color=#FF0000][strong]hr = lpAnimator.CreateInstance(GIFLib::CLSID_CGif)[/strong];[/font]
[/font] if (FAILED(hr))
{
_com_issue_error(hr);
}
lpRichEditOle->GetClientSite(&lpOleClientSite);
try
{
//获取OLE对象接口
hr = lpAnimator->QueryInterface(IID_IOleObject,(void**)&lpOleObject);
if (FAILED(hr))
{
AfxMessageBox("Error QueryInterface");
}
hr = lpOleObject->GetUserClassID(&clsid);
if (FAILED(hr))
{
AfxMessageBox("Error GetUserClassID");
}
//防止出现错误提示
lpOleObject->SetClientSite(NULL);
lpOleObject->SetClientSite(lpOleClientSite);
hr = ::CreateILockBytesOnHGlobal(NULL,TRUE,&lpLockBytes); //创建LOCKBYTE对象
if (FAILED(hr))
{
AfxThrowOleException(hr);
}
ASSERT(lpLockBytes != NULL);
hr = ::StgCreateDocfileOnILockBytes(lpLockBytes,
STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE,
0,&lpStorage);
if (FAILED(hr))
{
VERIFY(lpLockBytes->Release() == 0);
lpLockBytes = NULL;
AfxThrowOleException(hr);
}
ZeroMemory(&reobject,sizeof(REOBJECT)); //初始化一对象
reobject.cbStruct = sizeof(REOBJECT);
reobject.clsid = clsid;
reobject.cp = REO_CP_SELECTION;
reobject.dvaspect = DVASPECT_CONTENT;
reobject.dwFlags = REO_BLANK;
reobject.poleobj = lpOleObject;
reobject.polesite =lpOleClientSite;
reobject.pstg = lpStorage;
hr = lpRichEditOle->InsertObject(&reobject);
hr = lpAnimator->LoadFromFile(csFileName.AllocSysString());
if (FAILED(hr))
{
AfxThrowOleException(hr);
}
RedrawWindow(); //刷新窗体
lpOleClientSite->SaveObject();
OleSetContainedObject(lpOleObject,TRUE);
}
catch (CException* e)
{
e->Delete();
}
lpAnimator->Release();
lpStorage->Release();
return TRUE;
}
。