服务器已经启动了,为什么GetActiveObject()出错?::CLSIDFromProgID(L"AutoServer.Document", &clsid);
if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK) 
{
VERIFY(pUnk->QueryInterface(IID_IDispatch,(void**) &pDisp) == S_OK);
m_server.AttachDispatch(pDisp);
pUnk->Release();
//TRACE(" attach complete\n");

else 
{
if(!m_server.CreateDispatch(_T("AutoServer.Document")))
{
AfxMessageBox("Can't Create AutoServer!");
return -1;
}
m_server.ShowWindow();
}

解决方案 »

  1.   

    BOOL COleClientItem::CreateNewItem(REFCLSID clsid,
    OLERENDER render, CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc)
    {
    ASSERT_VALID(this);
    ASSERT(m_lpObject == NULL);     // one time only
    ASSERT(m_pDocument != NULL);
    ASSERT(lpFormatEtc == NULL ||
    AfxIsValidAddress(lpFormatEtc, sizeof(FORMATETC), FALSE)); // get storage for the object via virtual function call
    m_dwItemNumber = GetNewItemNumber();
    GetItemStorage();
    ASSERT(m_lpStorage != NULL); // fill in FORMATETC struct
    FORMATETC formatEtc;
    lpFormatEtc = _AfxFillFormatEtc(lpFormatEtc, cfFormat, &formatEtc); // attempt to create the object
    LPOLECLIENTSITE lpClientSite = GetClientSite();
    SCODE sc = ::OleCreate(clsid, IID_IUnknown,
    render, lpFormatEtc, lpClientSite, m_lpStorage, (LPLP)&m_lpObject);
    BOOL bResult = FinishCreate(sc); ASSERT_VALID(this);
    return bResult;
    }