我在程序中使用了COleClientItem::CreateFromFile(),相关代码如下:STDMETHODIMP COleElement::CreateOleClientItem(BSTR fileName)
{
         COleClientItem* pOleClientItem = new COleClientItem;         CString str; 
         str=fileName;    pOleClientItem->CreateFromFile(str);//程序运行到该点就崩溃
  
COleDocument* pOleDoc = new COleDocument; pOleDoc->AddItem(pOleClientItem);
        ......
}请教各位该如何使用CreateFromFile?

解决方案 »

  1.   

    文件路径是否正确,文件是否存在?
    传进去的文件名用TCHAR数组试试.
    另外是否加了AfxOleInit
      

  2.   

    可以参考msdn的例子
    MFCBIND: Active Document Container
      

  3.   

    BOOL CreateFromFile( LPCTSTR lpszFileName, REFCLSID clsid = CLSID_NULL, OLERENDER render = OLERENDER_DRAW, CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL );把后面的默认值带上试试
      

  4.   

    ParameterslpszFileNamePointer to the name of the file from which the OLE item is to be created.clsidReserved for future use.renderFlag specifying how the server will render the OLE item. For the possible values, seeOLERENDER in the OLE documentation.cfFormatSpecifies the Clipboard data format to be cached when creating the OLE item. lpFormatEtcPointer to aFORMATETC structure used if render is OLERENDER_FORMAT or OLERENDER_DRAW. Provide a value for this parameter only if you want to specify additional format information beyond the Clipboard format specified by cfFormat. If you omit this parameter, default values are used for the other fields in the FORMATETC structure.ResCall this function to create an embedded OLE item from a file. The framework calls this function from COleInsertDialog::CreateItem if the user chooses OK from the Insert Object dialog box when the Create from File button is selected.