VC中使用import方式引入word:
#import "D:\工具\office2000\Office\msword9.olb" rename("ExitWindows", "WordExitWindows")
生成msword9.tli和msword9.tlh
在程序中调用:
    Word::_DocumentPtr pDoc(disp);     //获取word对象
    if(pDoc!=NULL){
 Word::WindowPtr activeWin = pDoc->GetActiveWindow();    
 Word::PanePtr pane = activeWin->GetActivePane();
 Word::ViewPtr view = pane->GetView();
 Word::WdViewType vtype;
 vtype = view->GetType();
          .....
    }
编译后报错:
d:\...\debug\msword9.tli(27944) : error C2556: 'enum WdViewType __thiscall Word::View::GetType(void)' : overloaded function differs only by return type from 'enum Word::WdViewType __thiscall Word::View::GetType(void)'
d:\...\debug\msword9.tlh(25148) : see declaration of 'GetType'
d:\...\debug\msword9.tli(27944) : error C2371: 'GetType' : redefinition; different basic types
d:\...\debug\msword9.tlh(25148) : see declaration of 'GetType'
Error executing cl.exe.dsoflks.obj - 2 error(s), 0 warning(s)关于getview函数msword9.tli中的声明是这样的:
#pragma implementation_key(3684)
inline enum WdViewType Word::View::GetType ( ) {
    enum WdViewType _result;
    HRESULT _hr = get_Type(&_result);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _result;
}请问各位老大这个错误是什么意思,怎么解决?

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc/?id=1174
      

  2.   

    #include "stdafx.h"
    #import "G:\Program Files\Microsoft Office\Office11\MSWORD.OLB" named_guids raw_interfaces_only rename("ExitWindows", "wordExitWindows")
    void html_to_word()
    {
    printf("Automate word to save xxx.htm as onega.doc, test by masterz with VC.NET2003 on Windowx2003, Office2003\n");
    Word::_ApplicationPtr app;
    app.CreateInstance("Word.Application");
    app->put_DisplayAlerts(Word::wdAlertsNone);
    Word::DocumentsPtr docs;
    app->get_Documents(&docs);
    Word::_DocumentPtr doc;
    _variant_t vFileName("c:\\a.htm");
    _variant_t vOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
    _variant_t vTrue(VARIANT_TRUE);
    _variant_t vFalse(VARIANT_FALSE);
    docs->Open (
    /*[in]*/&vFileName,
    /*[in] VARIANT * ConfirmConversions*/&vOptional,
    /*[in] VARIANT * ReadOnly*/&vOptional,
    /*[in] VARIANT * AddToRecentFiles*/&vOptional,
    /*[in] VARIANT * PasswordDocument*/&vOptional,
    /*[in] VARIANT * PasswordTemplate*/&vOptional,
    /*[in] VARIANT * Revert*/&vOptional,
    /*[in] VARIANT * WritePasswordDocument*/&vOptional,
    /*[in] VARIANT * WritePasswordTemplate*/&vOptional,
    /*[in] VARIANT * Format*/&vOptional,
    /*[in] VARIANT * Encoding*/&vOptional,
    /*[in] VARIANT * Visible*/&vOptional,
    /*[in] VARIANT * OpenAndRepair*/&vOptional,
    /*[in] VARIANT * DocumentDirection*/&vOptional,
    /*[in] VARIANT * NoEncodingDialog*/&vOptional,
    /*[in] VARIANT * XMLTransform*/&vOptional ,
    /*[out,retval]*/ &doc );
    _variant_t vCopies((short)1);
    LPCTSTR save_file_name = _T("c:\\onega.doc");
    DeleteFile(save_file_name);
    _variant_t filename(save_file_name);
    _variant_t FileFormat((long)Word::wdFormatDocument);
    doc->SaveAs (&filename,&FileFormat);
    doc->put_Saved(VARIANT_TRUE);
    app->Quit(&vOptional,&vOptional,&vOptional);}
    int _tmain(int argc, _TCHAR* argv[])
    {
    CoInitialize(NULL);
    html_to_word();
    CoUninitialize();
    printf("program end!\n");
    return 0;
    }
      

  3.   

    http://www.vckbase.com/document/viewdoc/?id=1142
    http://www.vckbase.com/document/viewdoc/?id=1408