程序如下 ::CoInitialize(NULL);
_Application objWord;

// Convenient values declared as ColeVariants.
COleVariant covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

// Get the IDispatch pointer and attach it to the objWord object.
if (!objWord.CreateDispatch("Word.Application"))
{
AfxMessageBox("Couldn't get Word object.");
return;
}
结果总是返回Couldn't get Word object。请问都有哪些情况会导致CreateDispatch失败。(word已安装)   
 

解决方案 »

  1.   

    http://www.fruitfruit.com/vc/activex/word.txt
      

  2.   

    open the class wizard, select the automation tab, select "Add Class" ... "From a type library", and then select MSWORD.OLB from "C:\Program Files\Microsoft Office\Office\".
      

  3.   

    and #include  "msword.h"
      

  4.   

    因为你没有将OLE初始化
    AfxEnableControlContainer();
    AfxOleInit();
      

  5.   

    可能是杀毒软件的问题, 你先禁用杀毒软件,再试.NORTON ANTIVIRUS 和 KV300 有这种问题.
      

  6.   

    我同意 wangweixing2000(星)的做法。
    我以前就是那样作的,没有出错。
    运行结果是又打开了一个word应用程序。
      

  7.   

    是不是你程序中引用word的类型库的版本,和你当前系统word的版本不一致阿?