在控制台里面处理ms office word 2007 
vc 6.0
支持 MFC的控制台运用程序
code:
_Application     wordApp;  
if(!wordApp.CreateDispatch("Word.Application",NULL))
{
  cout<<"没有安装word"<<endl;
   return false ;
}
 这里返回的是NULL,如何解决
前提是我的装了 MS office word 2007 
也导入了 msword.olb
万分感谢!!!

解决方案 »

  1.   

    http://www.cppblog.com/ivenher/archive/2007/01/13/17592.html
      

  2.   

    有时候跟安装的OFFICE也有关,安装完整版,不要装精简版。
    还有COM要初始化,可到微软网站找实例测试。
      

  3.   

    我把我的代码贴出来吧!大家看看怎么回事急啊// AutoWord.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"
    #include "AutoWord.h"
    #include "msword.h"
    #include <fstream>#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // The one and only application objectCWinApp theApp;using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    int nRetCode = 0; // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
    // TODO: change error code to suit your needs
    cerr << _T("Fatal Error: MFC initialization failed") << endl;
    nRetCode = 1;
    }
    else
    {
    cout <<"程序入口"<<endl;
    AfxOleInit();  _Application     wordApp;     
    Documents     docs;     
    _Document     doc;     
    Range     aRange;  
    ofstream fout("C:\\Users\\lanhxh01\\Desktop"); wordApp.ReleaseDispatch();
    doc.ReleaseDispatch();
    docs.ReleaseDispatch();
         wordApp.m_bAutoRelease =true ;
    // open the word 
    if(!wordApp.CreateDispatch("Word.Application",NULL))
    {
      cout<<"没有安装word"<<endl;
       return false ; 
    } wordApp.SetVisible(TRUE); 
    docs=wordApp.GetDocuments(); 
        COleVariant  vTrue((short)TRUE),    
                          vFalse((short)FALSE),    
                          vOpt((long)DISP_E_PARAMNOTFOUND,  VT_ERROR);    
            

    doc=docs.Open(COleVariant("E:\\mytest\\CET\\Resouce\\listeningplus6\\8.doc"),
    vFalse,vTrue,vFalse,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt); aRange=doc.Range(vOpt,vOpt);
        aRange.WholeStory();
    CString str = aRange.GetText();
    fout<<str ;
    fout.close();
    doc.Close(vOpt,vOpt,vOpt);  
            wordApp.Quit(vOpt,vOpt,vOpt);        
            CoUninitialize();  
        cout <<"完成读取"<<endl;
    } return nRetCode;
    }这是所有的代码!!!求解决
      

  4.   

    VERIFY( AfxOleInit() );  
      

  5.   

    这个函数不行,要在前面加个    OleInitialize(NULL); 这样才可以。
    所以还是给我自己搞定了