Discussion:
MFC program: Excel Automation with Visual Studio 2005
(too old to reply)
Bryan
2006-08-04 04:56:02 UTC
Permalink
I followed the directions step by step as instructed at the following website:

http://support.microsoft.com/kb/307473/

When I try to compile the program, I get over 200 errors, all complaing
about the countents of CApplication.h and excel.tlh, which are generated by
Visual Studio I believe.

Examples of some of the warnings and errors are:

Warning 1 warning C4278: 'RGB': identifier in type library 'D:\\Program
Files\\Microsoft Office\\Office10\\EXCEL.EXE' is already a macro; use the
'rename' qualifier e:\exceltest\exceltest\capplication.h 3

Error 14 error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int)' : invalid
operand for __uuidof e:\exceltest\exceltest\debug\excel.tlh 1228

Error 31 error C2504: '_IMsoDispObj' : base class
undefined e:\exceltest\exceltest\debug\excel.tlh 1788

Any ideas how I can fix this so the project builds?
Alex Blekhman
2006-08-04 07:29:48 UTC
Permalink
Post by Bryan
I followed the directions step by step as instructed at the
http://support.microsoft.com/kb/307473/
When I try to compile the program, I get over 200 errors,
all complaing
about the countents of CApplication.h and excel.tlh, which
are generated by
Visual Studio I believe.
Warning 1 warning C4278: 'RGB': identifier in type library
'D:\\Program
Files\\Microsoft Office\\Office10\\EXCEL.EXE' is already a
macro; use the
'rename' qualifier e:\exceltest\exceltest\capplication.h 3
Error 14 error C2786: 'BOOL (__stdcall
*)(HDC,int,int,int,int)' : invalid
operand for __uuidof
e:\exceltest\exceltest\debug\excel.tlh 1228
Error 31 error C2504: '_IMsoDispObj' : base class
undefined e:\exceltest\exceltest\debug\excel.tlh 1788
Any ideas how I can fix this so the project builds?
You will need to rename collided names with `#import'
directve. For more info:

http://groups.google.com/group/microsoft.public.vc.language/msg/68115a45886de879

HTH
Alex
Bryan
2006-08-07 05:55:02 UTC
Permalink
Thank you for your reply. I added the import statements:

#import "D:\\Program Files\\Common Files\\Microsoft
Shared\\Office10\\MSO.DLL" rename("RGB", "ExclRGB")
rename("DocumentProperties", "ExclDocumentProperties") rename("SearchPath",
"ExclSearchPath")
#import "D:\\Program Files\\Common Files\\Microsoft
Shared\\VBA\\VBA6\\VBE6EXT.OLB"
#import "D:\\Program Files\\Microsoft Office\\Office10\\EXCEL.EXE"
rename("RGB", "ExclRGB") rename("CopyFile", "ExclCopyFile")
rename("ReplaceText", "ExclReplaceText") rename("DialogBox", "ExclDialogBox")




Now there are only 20 errors and 2 warnings. I still do not know how to fix
these though. It appears to be related to Visual Basic. The errors are:

Error 1 error C2146: syntax error : missing ';' before identifier
'VBProject' e:\exceltest\exceltest\debug\excel.tlh 61278
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 61278
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 61278
Error 4 error C2146: syntax error : missing ';' before identifier
'GetVBProject' e:\exceltest\exceltest\debug\excel.tlh 61643
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 61643
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 61643
Warning 7 warning C4183: 'GetVBProject': missing return type; assumed to be
a member function returning
'int' e:\exceltest\exceltest\debug\excel.tlh 61643
Error 8 error C2146: syntax error : missing ';' before identifier
'VBE' e:\exceltest\exceltest\debug\excel.tlh 64876
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 64876
Error 10 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 64876
Error 11 error C2146: syntax error : missing ';' before identifier
'GetVBE' e:\exceltest\exceltest\debug\excel.tlh 65877
Error 12 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 65877
Error 13 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 65877
Warning 14 warning C4183: 'GetVBE': missing return type; assumed to be a
member function returning 'int' e:\exceltest\exceltest\debug\excel.tlh 65877
Error 15 error C2143: syntax error : missing ';' before
'Excel::_Workbook::GetVBProject' e:\exceltest\exceltest\debug\excel.tlh 81549
Error 16 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 81549
Error 17 error C2497: '_VBProjectPtr' : 'implementation_key' can only be
applied to function declarations e:\exceltest\exceltest\debug\excel.tlh 81549
Error 18 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 81549
Error 19 error C2143: syntax error : missing ';' before
'Excel::_Application::GetVBE' e:\exceltest\exceltest\debug\excel.tlh 82209
Error 20 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 82209
Error 21 error C2497: 'VBEPtr' : 'implementation_key' can only be applied to
function declarations e:\exceltest\exceltest\debug\excel.tlh 82209
Error 22 error C4430: missing type specifier - int assumed. Note: C++ does
not support default-int e:\exceltest\exceltest\debug\excel.tlh 82209
Alex Blekhman
2006-08-07 07:18:04 UTC
Permalink
Post by Bryan
#import "D:\\Program Files\\Common Files\\Microsoft
Shared\\Office10\\MSO.DLL" rename("RGB", "ExclRGB")
rename("DocumentProperties", "ExclDocumentProperties")
rename("SearchPath",
"ExclSearchPath")
#import "D:\\Program Files\\Common Files\\Microsoft
Shared\\VBA\\VBA6\\VBE6EXT.OLB"
#import "D:\\Program Files\\Microsoft
Office\\Office10\\EXCEL.EXE"
rename("RGB", "ExclRGB") rename("CopyFile",
"ExclCopyFile")
rename("ReplaceText", "ExclReplaceText")
rename("DialogBox", "ExclDialogBox")
Now there are only 20 errors and 2 warnings. I still do
not know how to fix
these though. It appears to be related to Visual Basic.
According to identifier names in error they are related to
Excel object model. On my machine these objects are defined
in "C:\Program Files\Microsoft Office\OFFICE11\XL5EN32.OLB"
file. So, you need to #import this library, too. I think you
will need to rename a couple of name collisions, as well.
However, first try to import it as it is. If there are
errors, then start renaming identifiers.

As a general way to cope with such problems I'd suggest you
to get acquaint with "OLE/COM Object Viewer" tool. It's
invaluable when you need to determine which module
implements certain interface or CoClass.

Usually, when I'm not certain about implementation of some
component I look it up in MSDN It can be stated there which
DLL/TLB implements it. Then I open this DLL/TLB with
"OLE/COM Object Viewer" to see what's going on there. If
MSDN doesn't point to DLL/TLB/OCX, then I start searching
with "OLE/COM Object Viewer" for known interface or typelib
or coclass. From there you will be able to reverse engineer
all implementation details.

HTH
Alex

Loading...