构建 MFC 自动化示例(使用 OLE 自动化访问 Excel)。 无法编译
我正在尝试构建 http://support.microsoft.com 中描述的示例/kb/178749/EN-US/,以便构建一个使用自动化以编程方式访问 Excel 的应用程序。 我有 Visual C++ 2005/Visual Studio 2005。有些指令并不完全匹配(大多数是类向导),但总体思路似乎是相同的。
问题:使用“新类”创建包装类后,我最终没有得到 excel.h 文件。 所以我不能按照步骤 13 中指定的方式 #include 该文件。我确实在我的 Windebug 目录中得到了一个 excel.tlh 和一个 excel.tli,但这似乎不起作用。 我尝试了所有命令
#include "stdafx.h"
#include "debug/excel.tli"
#include "debug/excel.tlh"
...包括将其中一个文件排除在编译之外,但最终仍然出现大量编译错误。
以下是上述 #include 的前 5 个编译错误:
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2653: 'Adjustments' : is not a class or namespace name
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2146: syntax error : missing ';' before identifier 'GetParent'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2433: 'IDispatchPtr' : 'inline' not permitted on data declarations
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(16) : error C3861: 'get_Parent': identifier not found
这是这些包含的前 5 个错误:
#include "stdafx.h"
#include "debug/excel.tlh"
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(550) : error C3121: cannot change GUID for class 'IFilter'
1> c:\program files\microsoft sdks\windows\v6.0\include\comdef.h(483) : see declaration of 'IFilter'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int)' : invalid operand for __uuidof
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C2923: '_com_IIID' : 'Rectangle' is not a valid template type argument for parameter '_Interface'
1> c:\program files\microsoft sdks\windows\v6.0\include\wingdi.h(3667) : see declaration of 'Rectangle'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C3203: '_com_IIID' : unspecialized class template can't be used as a template argument for template parameter '_IIID', expected a real type
这是这些包含的前 5 个错误:
#include "stdafx.h"
#include "debug/excel.tli"
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2653: 'Adjustments' : is not a class or namespace name
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2146: syntax error : missing ';' before identifier 'GetParent'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2433: 'IDispatchPtr' : 'inline' not permitted on data declarations
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
提前致谢。
I'm trying to build the example described at http://support.microsoft.com/kb/178749/EN-US/ in order to build an application that programatically accesses Excel using Automation. I have Visual C++ 2005/Visual Studio 2005. Some of the instructions don't exactly match up (classwizard, mostly), but the general idea seems to be the same.
Problems: I don't end up with an excel.h file after using the "new class" to create my wrapper classes. So I can' t #include that file as it specifies in step 13. I do get a excel.tlh and an excel.tli in my windebug directory, but that doesn't seem to work. I tried all orders for
#include "stdafx.h"
#include "debug/excel.tli"
#include "debug/excel.tlh"
... including leaving one of those files out of the compile, but I still end up with a ton of compile errors.
Here's the top 5 compile errors with the above #includes:
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2653: 'Adjustments' : is not a class or namespace name
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2146: syntax error : missing ';' before identifier 'GetParent'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2433: 'IDispatchPtr' : 'inline' not permitted on data declarations
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(16) : error C3861: 'get_Parent': identifier not found
Here's the top 5 errors with these includes:
#include "stdafx.h"
#include "debug/excel.tlh"
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(550) : error C3121: cannot change GUID for class 'IFilter'
1> c:\program files\microsoft sdks\windows\v6.0\include\comdef.h(483) : see declaration of 'IFilter'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int)' : invalid operand for __uuidof
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C2923: '_com_IIID' : 'Rectangle' is not a valid template type argument for parameter '_Interface'
1> c:\program files\microsoft sdks\windows\v6.0\include\wingdi.h(3667) : see declaration of 'Rectangle'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tlh(1541) : error C3203: '_com_IIID' : unspecialized class template can't be used as a template argument for template parameter '_IIID', expected a real type
Here's the top 5 errors with these includes:
#include "stdafx.h"
#include "debug/excel.tli"
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2653: 'Adjustments' : is not a class or namespace name
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2146: syntax error : missing ';' before identifier 'GetParent'
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C2433: 'IDispatchPtr' : 'inline' not permitted on data declarations
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\sniles\documents\visual studio 2005\source10\testole\testole\debug\excel.tli(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道这是否有帮助,但通常您会
#import
类型库,但不会#include
.tli 和 .tlh 文件(#import
隐式执行此操作)。另外,请记住在 MFC 中调用 COM 服务器有两种方法。
使用
#import
,它基本上创建智能ATL指针来创建COM对象并调用方法。使用类向导创建
IDispatch
样式类包装器,以创建 COM 对象并调用方法。I don't know if this helps but generally you
#import
the type library but you do NOT#include
the .tli and .tlh files (the#import
implicitly does this).Also, remember there are two ways of calling a COM server in MFC.
Use
#import
which basically creates smart ATL pointers to create COM objects and call methods.Use the class wizard to create an
IDispatch
style class wrapper to create COM object and call the methods.根据 Nick 的要求,我发布了构建错误输出,并遵循
vbe6ext.tlh
文件,直至出现错误:At Nick's request, I'm posting the build error output and following that the
vbe6ext.tlh
file, up to the error:我不熟悉 ClassWizard 包装器生成器,但看起来它可能#imported了没有命名空间的 Excel COM 类型库,并且您与 SDK 头文件发生了冲突。 检查
.tlh
文件并确保定义周围有命名空间。 如果没有,我会考虑使用 #import 以更手动(但更安全)的方式导入它。直接使用#import查看; 它将在构建目录中生成
.tlh
和.tli
文件,然后您可以将目录与CComPtr<>
等一起使用。 我发现这比使用 CW 包装类要简单得多。 无论如何,这就是我的建议。I'm not familiar with the ClassWizard wrapper generator, but it looks like it may have #imported the Excel COM type library without a namespace, and you're getting conflicts with the SDK header files. Check the
.tlh
file and ensure there's a namespace around the definitions. If not, I'd look at importing it the more manual (but safer) way using #import.Check out using #import directly; it will generate the
.tlh
and.tli
files in the build directory, which you can then use directory withCComPtr<>
and the like. I've found that to be much more straightforward than using CW wrapper classes. That's my advice anyway.