VS2005 (C++, MFC) и Excel 2003
От: KneLL Украина  
Дата: 01.08.06 13:49
Оценка:
Читал статьи на сайте про Office & MFС, но как-то не вышло сделать тоже самое в сабжевой среде.
Выполнял следующие шаги, описанные на http://support.microsoft.com/kb/q178749/
1. Project -> Add Class
2. MFC Class from TypeLib
3. Либо из Registry(Microsoft Excel 11.0 Type Library) либо прямо из файла
4. Добавляю один класс Application (Переименовываю в _Application).
5.
#include "_Application.h"

6. И, не создав ни единого объекта, получаю мнооооого ошибок по генерируемому файлу Debug\excel.tlh:
 warning C4278: 'RGB': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'RGB': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4192: automatically excluding 'IFont' while importing type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE'
 warning C4192: automatically excluding 'IPicture' while importing type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE'
 warning C4278: 'DialogBox': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'CopyFile': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'ReplaceText': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'ReplaceText': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'RGB': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'RGB': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'CopyFile': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 warning C4278: 'DialogBox': identifier in type library 'E:\\knell\\dev\\cpp\\AmwayViewer\\EXCEL.EXE' is already a macro; use the 'rename' qualifier
 error C2371: 'FontPtr' : redefinition; different basic types
    d:\program files\microsoft visual studio 8\vc\include\comdef.h(312) : see declaration of 'FontPtr'
 error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int)' : invalid operand for __uuidof
 error C2923: '_com_IIID' : 'Rectangle' is not a valid template type argument for parameter '_Interface'
    d:\program files\microsoft visual studio 8\vc\platformsdk\include\wingdi.h(3514) : see declaration of 'Rectangle'
 error C3203: '_com_IIID' : unspecialized class template can't be used as a template argument for template parameter '_IIID', expected a real type
 error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int,int,int,int,int)' : invalid operand for __uuidof
 error C2923: '_com_IIID' : 'Arc' is not a valid template type argument for parameter '_Interface'
    d:\program files\microsoft visual studio 8\vc\platformsdk\include\wingdi.h(2765) : see declaration of 'Arc'
 '_com_IIID' : unspecialized class template can't be used as a template argument for template parameter '_IIID', expected a real type
 'PicturePtr' : redefinition; different basic types
    d:\program files\microsoft visual studio 8\vc\include\comdef.h(326) : see declaration of 'PicturePtr'
 error C2504: '_IMsoDispObj' : base class undefined
 error C2504: '_IMsoDispObj' : base class undefined
 error C2504: '_IMsoDispObj' : base class undefined
 error C2146: syntax error : missing ';' before identifier 'GetRGB'
 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 warning C4183: 'GetRGB': missing return type; assumed to be a member function returning 'int'
 error C2061: syntax error : identifier 'MsoRGBType'
 error C2061: syntax error : identifier 'MsoRGBType'
 error C2061: syntax error : identifier 'MsoRGBType'
 error C2504: '_IMsoDispObj' : base class undefined
 error C2146: syntax error : missing ';' before identifier 'GetTransparencyColor'
 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

и так далее, более 100 ошибок...

Как побороть??
Re: VS2005 (C++, MFC) и Excel 2003
От: Master Yoda Великобритания  
Дата: 01.08.06 14:07
Оценка:
Здравствуйте, KneLL, Вы писали:

KLL>1. Project -> Add Class

KLL>2. MFC Class from TypeLib

Используй лучше #import, за примерами в поиск (например http://rsdn.ru/Forum/?mid=1706306
Автор: Константин Ленин
Дата: 01.03.06
)
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
It is always bad to give advices, but you will be never forgiven for a good one.
Oscar Wilde
Re[2]: VS2005 (C++, MFC) и Excel 2003
От: KneLL Украина  
Дата: 01.08.06 14:12
Оценка:
Здравствуйте, Master Yoda, Вы писали:

MY>Используй лучше #import, за примерами в поиск (например http://rsdn.ru/Forum/?mid=1706306
Автор: Константин Ленин
Дата: 01.03.06
)


Спасибочки, тогда такой дурацкий вопрос. При таком импорте данное приложение будет работать с любым офисом, то есть все функции Excel статически слинкуются или нет? Или нужно будет таскать еще и DDL ?
Re[3]: VS2005 (C++, MFC) и Excel 2003
От: astral_marine  
Дата: 01.08.06 15:16
Оценка:
Здравствуйте, KneLL, Вы писали:
KLL>Спасибочки, тогда такой дурацкий вопрос. При таком импорте данное приложение будет работать с любым офисом, то есть все функции Excel статически слинкуются или нет? Или нужно будет таскать еще и DDL ?

Линкуются динамически через ком. Из этих ДЛЛ берется только информация для компилятора, потом в работе они нужны только для самого офиса.
Скорее всего (99,5%), что будет работать и с последующими версиями офиса, и возможно даже с более ранними. Здесь нужно смотреть и сравнивать интерфейсы офисов.
Re[2]: VS2005 (C++, MFC) и Excel 2003
От: KneLL Украина  
Дата: 01.08.06 15:26
Оценка:
Здравствуйте, Master Yoda, Вы писали:

MY>Используй лучше #import, за примерами в поиск (например http://rsdn.ru/Forum/?mid=1706306
Автор: Константин Ленин
Дата: 01.03.06
)


таки я балбес наверное Но..

1>Import MS Excel library...
1>error C2259: 'Excel::Workbooks' : cannot instantiate abstract class
1>        due to following members:
1>        'HRESULT IUnknown::QueryInterface(const IID &,void **)' : is abstract
и т.д. все методы класса...


сделал всё по примеру...
Re[3]: VS2005 (C++, MFC) и Excel 2003
От: algol Россия about:blank
Дата: 01.08.06 16:12
Оценка:
Здравствуйте, KneLL, Вы писали:

KLL>
1>>Import MS Excel library...
1>>error C2259: 'Excel::Workbooks' : cannot instantiate abstract class
1>>        due to following members:
1>>        'HRESULT IUnknown::QueryInterface(const IID &,void **)' : is abstract
KLL>и т.д. все методы класса...
KLL>


Надо юзать не сами интерфейсы, а смарт-пойнтеры, в данном случае WorkbooksPtr.
Re[4]: VS2005 (C++, MFC) и Excel 2003
От: KneLL Украина  
Дата: 01.08.06 19:45
Оценка:
Здравствуйте, algol, Вы писали:
A>Надо юзать не сами интерфейсы, а смарт-пойнтеры, в данном случае WorkbooksPtr.

Вот же!! Пойду курить СОМ...
Спасибо!
Re[4]: VS2005 (C++, MFC) и Excel 2003
От: KneLL Украина  
Дата: 01.08.06 21:25
Оценка:
Здравствуйте, algol, Вы писали:

A>Надо юзать не сами интерфейсы, а смарт-пойнтеры, в данном случае WorkbooksPtr.


Чо т совсем запарился

_ApplicationPtr app;
WorkbooksPtr books;

books = app->Workbooks;


вылетает на operator->() для app. Я так понял, что необходимо создать этот самый _Application, но как? new вроде бы не подходит, аналог CreateObject из VB я даже не знаю... Подскажите, плиз...
Re: VS2005 (C++, MFC) и Excel 2003
От: KneLL Украина  
Дата: 01.08.06 22:14
Оценка:
Во, нашел простой и удобный способ!
http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c4307/
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.