我自己在把Gif89a注册完,#import "C:\显示GIF89a的控件\Debug\Gif89.dll"named_guids导到自己的
程序当中。结果显示不来,双击时出错。主要代码如下:
(要整个即 测试代码+Gif89a.dll   QQ联系:283311186)
BOOL CRichEditEx::Insert()
{
    IRichEditOleCallback FAR *m_lpRichEditCallBack = NULL;
    LPLOCKBYTES lpLockBytes = NULL;
    SCODE sc;
    HRESULT hr;
    IRichEditOle *lpRichEditOle=NULL;
       //print to RichEdit' s IClientSite
    LPOLECLIENTSITE m_lpClientSite;
       //A smart point to IGif89a
    GIF89Lib::IGif89aPtr m_lpGif89a;
       //ptr 2 storage
    LPSTORAGE m_lpStorage;
       //the object 2 b insert 2
    LPOLEOBJECTm_lpObject;
       //Create lockbytes
    sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
    if (sc != S_OK)
AfxThrowOleException(sc);
    ASSERT(lpLockBytes != NULL);
       //use lockbytes to create storage
    sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);
    if (sc != S_OK)
{
    VERIFY(lpLockBytes->Release() == 0);
lpLockBytes = NULL;
AfxThrowOleException(sc);
}
    ASSERT(m_lpStorage != NULL);
    
          try
            {
           //Initlize COM interface
         hr = ::CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
         if( FAILED(hr) )
_com_issue_error(hr); 
//Get Gif89a object
//here, I used a smart point, so I do not need to free it
    hr = m_lpGif89a.CreateInstance(GIF89Lib::CLSID_Gif89a);
        if( FAILED(hr) )
_com_issue_error(hr);
CString strPicPath = "d:\\mm.gif";//gif动画
BSTR path = strPicPath.AllocSysString();
//Load the gif
m_lpGif89a->PutEmbed(FALSE);
m_lpGif89a->PutEnabled(TRUE);
m_lpGif89a->PutAutoSize(TRUE);
         m_lpGif89a->PutFileName(path);
   
m_lpGif89a->Play();
//get the ClientSite of the very RichEditCtrl
    //lpRichEditOle = GetIRichEditOle();
//::SendMessage(m_RichEditEx.m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&lpRichEditOle);
lpRichEditOle=this->GetIRichEditOle();
lpRichEditOle->GetClientSite(&m_lpClientSite);
ASSERT(m_lpClientSite != NULL);
//get the IOleObject
hr =m_lpGif89a->QueryInterface(IID_IOleObject,(void**)&m_lpObject);
if( FAILED(hr) )
_com_issue_error(hr);
//Set it 2 b inserted
OleSetContainedObject(m_lpObject,TRUE);
//2 insert in 2 richedit, you need a struct of REOBJECT
REOBJECT reobject;
ZeroMemory(&reobject, sizeof(REOBJECT));
reobject.cbStruct = sizeof(REOBJECT);
CLSID clsid;
sc = m_lpObject->GetUserClassID(&clsid);
if (sc != S_OK)
AfxThrowOleException(sc);
  //set clsid
reobject.clsid = clsid;
  //can be selected
reobject.cp = REO_CP_SELECTION;
  //content, but not static
reobject.dvaspect = DVASPECT_CONTENT;
  //goes in the same line of text line
reobject.dwFlags = REO_BELOWBASELINE; //REO_RESIZABLE |
reobject.dwUser = 0;
  //the very object
reobject.poleobj = m_lpObject;
  //client site contain the object
reobject.polesite = m_lpClientSite;
  //the storage 
reobject.pstg = m_lpStorage;
SIZEL sizel;
sizel.cx = sizel.cy = 0;
reobject.sizel = sizel;
 //SendMessage(EM_SETOLECALLBACK,0,(LPARAM)m_lpRichEditCallBack);
this->GetIRichEditOle()->InsertObject(&reobject);
SendMessage(EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
      m_lpObject->DoVerb(OLEIVERB_UIACTIVATE,NULL,m_lpClientSite,0,this-  >m_hWnd, NULL);
      m_lpObject->DoVerb(OLEIVERB_SHOW,NULL,m_lpClientSite,0,this->m_hWnd,  NULL);
   //redraw the window to show animation
RedrawWindow();
if (m_lpClientSite)
{
m_lpClientSite->Release();
m_lpClientSite = NULL;
}
if (m_lpObject)
{
//m_lpRichEditCallBack->Release();
m_lpObject->Release();
m_lpObject = NULL;
}
if (m_lpStorage)
{
m_lpStorage->Release();
m_lpStorage = NULL;
}
SysFreeString(path);
}
       catch( _com_error e )
   {
AfxMessageBox(e.ErrorMessage());
//::CoUninitialize();
   }
    return TRUE;   
}