none
vs2005下引入CWorkbooks.h出错 RRS feed

  • 问题

  • 我的项目include CWorkbooks.h后编译出错(本来没错的),我的运行环境是VS2005,please help me,thanks in advance!我的e_mail:619677621@qq.com
    直接在MFC添加类向导加入 CWorkbooks.h时 CWorkbooks.h如下:
    #import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE" no_namespace
    class CWorkbooks : public COleDispatchDriver
    {
    public:
     CWorkbooks(){} // 调用 COleDispatchDriver 默认构造函数
     CWorkbooks(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
    ..........
    编译后有:
    错误 14 error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int)' : invalid operand for __uuidof  excel.tlh 1297 
    错误 15 error C2923: '_com_IIID' : 'Rectangle' is not a valid template type argument for parameter '_Interface'  excel.tlh 1297 
    错误 16 error C3203: '_com_IIID' : unspecialized class template can't be used as a template argument for template parameter '_IIID', expected a real type  excel.tlh 1297 
    等个666错误

    后来把CWorkbooks.h的“#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE" no_namespace”替代为:
    #import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE11\\mso.dll" rename("RGB","MSRGB")
    #import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\VBA6\\VBE6EXT.OLB" raw_interfaces_only rename("Reference","ignorethis"), rename("VBE", "testVBE")
    #import "C:\\Program Files\\Microsoft Office\\Office11\\EXCEL.EXE" exclude("IFont","IPicture") rename("RGB","ignorethis"),rename("DialogBox","ignorethis"),rename("VBE","testVBE"),rename("ReplaceText","EReplaceText"),rename("CopyFile","ECopyFile"),rename("FindText","EFindText"),rename("NoPrompt","ENoPrompt")

    编译后只有57个错误,错误虽然减少了但还是解决不了,上网找了很多资料,都解决不了,希望哪位高手帮一下我这个菜鸟吧。 以下为改后的错误列表:
    1 error C2146: syntax error : missing ';' before identifier 'get_Application' cworkbooks.h 24 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int cworkbooks.h 24 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int cworkbooks.h 25 5 error C2146: syntax error : missing ';' before identifier 'get_Creator' cworkbooks.h 30 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int cworkbooks.h 30 7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int cworkbooks.h 31 9 error C2061: syntax error : identifier 'Parameter' cworkbooks.h 42 10 error C2061: syntax error : identifier 'Parameter' cworkbooks.h 55 11 error C2146: syntax error : missing ';' before identifier 'get__Default' cworkbooks.h 62 12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int cworkbooks.h 62 13 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int cworkbooks.h 63 15 error C2065: 'Application' : undeclared identifier cworkbooks.h 26 .........................
    2009年3月31日 13:21

答案

  • 我这个问题在vs2003里面已经解决了,直接导入就可以了,仔细比较两者生成的CWorkbooks.h,是有区别的!
    vs2003的CWorkbooks.h
    class CWorkbooks : public COleDispatchDriver
    {
    public:
     CWorkbooks(){} // 调用 COleDispatchDriver 默认构造函数
     CWorkbooks(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
     CWorkbooks(const CWorkbooks& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

     // 属性
    public:

     // 操作
    public:


     // Workbooks 方法
    public:
     LPDISPATCH get_Application()
     {
      LPDISPATCH result;
      InvokeHelper(0x94, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
      return result;
     }

    vs2005的CWorkbooks.h

    #import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE" no_namespace
    // CWorkbooks 包装类
    class CWorkbooks : public COleDispatchDriver
    {
    public:
     CWorkbooks(){} // 调用 COleDispatchDriver 默认构造函数
     CWorkbooks(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
     CWorkbooks(const CWorkbooks& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}// 属性
    public: // 操作
    public:
    // IParameters 方法
    public:
     Application get_Application()
     {
      Application result;
      InvokeHelper(0x94, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
      return result;
     }
     XlCreator get_Creator()
     {
      XlCreator result;
      InvokeHelper(0x95, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
      return result;
     }

    2009年4月3日 1:29

全部回复

  • 如果你导入类型库的话不需要再创建MFC封装类。如果你决定用MFC封装类,那么不要在同一个名称空间内再倒入类型库。如果导入的类型库中有和Windows SDK宏冲突的名称,哟娜rename语句重新命名。
    MSMVP VC++
    2009年4月1日 14:04
    版主
  • 直接注释掉
    #import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE" no_namespace
    试试

    -----------------------------------------------------------
    EMail:Matrix_xx@126.com
    2009年4月2日 1:42
  • 我这个问题在vs2003里面已经解决了,直接导入就可以了,仔细比较两者生成的CWorkbooks.h,是有区别的!
    vs2003的CWorkbooks.h
    class CWorkbooks : public COleDispatchDriver
    {
    public:
     CWorkbooks(){} // 调用 COleDispatchDriver 默认构造函数
     CWorkbooks(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
     CWorkbooks(const CWorkbooks& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

     // 属性
    public:

     // 操作
    public:


     // Workbooks 方法
    public:
     LPDISPATCH get_Application()
     {
      LPDISPATCH result;
      InvokeHelper(0x94, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
      return result;
     }

    vs2005的CWorkbooks.h

    #import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE" no_namespace
    // CWorkbooks 包装类
    class CWorkbooks : public COleDispatchDriver
    {
    public:
     CWorkbooks(){} // 调用 COleDispatchDriver 默认构造函数
     CWorkbooks(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
     CWorkbooks(const CWorkbooks& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}// 属性
    public: // 操作
    public:
    // IParameters 方法
    public:
     Application get_Application()
     {
      Application result;
      InvokeHelper(0x94, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
      return result;
     }
     XlCreator get_Creator()
     {
      XlCreator result;
      InvokeHelper(0x95, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
      return result;
     }

    2009年4月3日 1:29