ken9865432

I tried to do the following example in vc++ 2005 but it wont comiple.

It returns like 300 errors in excel.thl file. I havent even done the coding part, i just

imported the CApplication.h and turned on the runtime support compiler option (/clr:oldSyntax)

like the kb says and tried to compile.. help..

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



Re: Visual C++ General using excel type library in vc++2005


Re: Visual C++ General using excel type library in vc++2005

ken9865432

hi

Thanks for the tip. but still returns comilation errors.

How do you remove these errors

Error 1 error C2504: '_IMsoDispObj' : base class undefined
Error 2 error C2504: '_IMsoDispObj' : base class undefined
Error 3 error C2504: '_IMsoDispObj' : base class undefined
Error 4 error C2146: syntax error : missing ';' before iden
Error 5 error C4430: missing type specifier - int assumed.
Error 6 error C4430: missing type specifier - int assumed.
Warning 7 warning C4183: 'Getignorethis': missing return ty
Error 8 error C2061: syntax error : identifier 'MsoRGBType'
Error 9 error C2061: syntax error : identifier 'MsoRGBType'
Error 10 error C2061: syntax error : identifier 'MsoRGBType
Error 11 error C2504: '_IMsoDispObj' : base class undefined
Error 12 error C2504: '_IMsoDispObj' : base class undefined
Error 13 error C2504: '_IMsoDispObj' : base class undefined
Error 14 error C2504: '_IMsoDispObj' : base class undefined
Error 15 error C2146: syntax error : missing ';' before ide
Error 16 error C4430: missing type specifier - int assumed.
Error 17 error C4430: missing type specifier - int assumed.
Warning 18 warning C4183: 'GetTransparencyColor': missing r191
Error 19 error C2061: syntax error : identifier 'MsoRGBType
Error 20 error C2061: syntax error : identifier 'MsoRGBType
Error 21 error C2061: syntax error : identifier 'MsoRGBType
Error 22 error C2504: '_IMsoDispObj' : base class undefined
Error 23 error C2504: '_IMsoDispObj' : base class undefined
Error 24 error C2504: '_IMsoDispObj' : base class undefined
Error 25 error C2504: '_IMsoDispObj' : base class undefined
Error 26 error C2146: syntax error : missing ';' before ide
Error 27 error C4430: missing type specifier - int assumed.
Error 28 error C4430: missing type specifier - int assumed.
Error 29 error C2146: syntax error : missing ';' before ide
Error 30 error C4430: missing type specifier - int assumed.
Error 31 error C4430: missing type specifier - int assumed.
Error 32 error C2146: syntax error : missing ';' before ide
Error 33 error C4430: missing type specifier - int assumed.
Error 34 error C4430: missing type specifier - int assumed.
Warning 35 warning C4183: 'GetScripts': missing return type
Error 36 error C2146: syntax error : missing ';' before ide
Error 37 error C4430: missing type specifier - int assumed.
Error 38 error C4430: missing type specifier - int assumed.
Warning 39 warning C4183: 'GetMailEnvelope': missing return
Error 40 error C2146: syntax error : missing ';' before ide
Error 41 error C4430: missing type specifier - int assumed.
Error 42 error C4430: missing type specifier - int assumed.
Error 43 error C2146: syntax error : missing ';' before ide
Error 44 error C4430: missing type specifier - int assumed.
Error 45 error C4430: missing type specifier - int assumed.
Error 46 error C2146: syntax error : missing ';' before ide
Error 47 error C4430: missing type specifier - int assumed.
Error 48 error C4430: missing type specifier - int assumed.
Warning 49 warning C4183: 'GetScript': missing return type;
Error 50 error C2146: syntax error : missing ';' before ide
Error 51 error C4430: missing type specifier - int assumed.
Error 52 error C4430: missing type specifier - int assumed.
Warning 53 warning C4183: 'GetCanvasItems': missing return
Error 54 error C2146: syntax error : missing ';' before ide
Error 55 error C4430: missing type specifier - int assumed.
Error 56 error C4430: missing type specifier - int assumed.
Error 57 error C2146: syntax error : missing ';' before ide
Error 58 error C4430: missing type specifier - int assumed.
Error 59 error C4430: missing type specifier - int assumed.
Warning 60 warning C4183: 'GetCanvasItems': missing return
Error 61 error C2146: syntax error : missing ';' before ide
Error 62 error C4430: missing type specifier - int assumed.
Error 63 error C4430: missing type specifier - int assumed.
Error 64 error C2146: syntax error : missing ';' before ide
Error 65 error C4430: missing type specifier - int assumed.
Error 66 error C4430: missing type specifier - int assumed.
Error 67 error C2146: syntax error : missing ';' before ide
Error 68 error C4430: missing type specifier - int assumed.
Error 69 error C4430: missing type specifier - int assumed.
Warning 70 warning C4183: 'GetScripts': missing return type
Error 71 error C2146: syntax error : missing ';' before ide
Error 72 error C4430: missing type specifier - int assumed.
Error 73 error C4430: missing type specifier - int assumed.
Warning 74 warning C4183: 'GetMailEnvelope': missing return
Error 75 error C2146: syntax error : missing ';' before ide
Error 76 error C4430: missing type specifier - int assumed.
Error 77 error C2208: 'Excel::Scripts' : no members defined
Error 78 fatal error C1903: unable to recover from previous
Error 79 error C2504: '_IMsoDispObj' : base class undefined
Error 80 error C2504: '_IMsoDispObj' : base class undefined
Error 81 error C2504: '_IMsoDispObj' : base class undefined
Error 82 error C2146: syntax error : missing ';' before ide
Error 83 error C4430: missing type specifier - int assumed.
Error 84 error C4430: missing type specifier - int assumed.
Warning 85 warning C4183: 'Getignorethis': missing return t
Error 86 error C2061: syntax error : identifier 'MsoRGBType
Error 87 error C2061: syntax error : identifier 'MsoRGBType
Error 88 error C2061: syntax error : identifier 'MsoRGBType
Error 89 error C2504: '_IMsoDispObj' : base class undefined
Error 90 error C2504: '_IMsoDispObj' : base class undefined
Error 91 error C2504: '_IMsoDispObj' : base class undefined
Error 92 error C2504: '_IMsoDispObj' : base class undefined
Error 93 error C2146: syntax error : missing ';' before ide
Error 94 error C4430: missing type specifier - int assumed.
Error 95 error C4430: missing type specifier - int assumed.
Warning 96 warning C4183: 'GetTransparencyColor': missing r191
Error 97 error C2061: syntax error : identifier 'MsoRGBType
Error 98 error C2061: syntax error : identifier 'MsoRGBType
Error 99 error C2061: syntax error : identifier 'MsoRGBType
Error 100 error C2504: '_IMsoDispObj' : base class undefine
Error 101 error C2504: '_IMsoDispObj' : base class undefine
Error 102 error C2504: '_IMsoDispObj' : base class undefine
Error 103 error C2504: '_IMsoDispObj' : base class undefine
Error 104 error C2146: syntax error : missing ';' before id
Error 105 error C4430: missing type specifier - int assumed
Error 106 error C4430: missing type specifier - int assumed
Error 107 error C2146: syntax error : missing ';' before id
Error 108 error C4430: missing type specifier - int assumed
Error 109 error C4430: missing type specifier - int assumed
Error 110 error C2146: syntax error : missing ';' before id
Error 111 error C4430: missing type specifier - int assumed
Error 112 error C4430: missing type specifier - int assumed
Warning 113 warning C4183: 'GetScripts': missing return typ
Error 114 error C2146: syntax error : missing ';' before id
Error 115 error C4430: missing type specifier - int assumed
Error 116 error C4430: missing type specifier - int assumed
Warning 117 warning C4183: 'GetMailEnvelope': missing retur
Error 118 error C2146: syntax error : missing ';' before id
Error 119 error C4430: missing type specifier - int assumed
Error 120 error C4430: missing type specifier - int assumed
Error 121 error C2146: syntax error : missing ';' before id
Error 122 error C4430: missing type specifier - int assumed
Error 123 error C4430: missing type specifier - int assumed
Error 124 error C2146: syntax error : missing ';' before id
Error 125 error C4430: missing type specifier - int assumed
Error 126 error C4430: missing type specifier - int assumed
Warning 127 warning C4183: 'GetScript': missing return type
Error 128 error C2146: syntax error : missing ';' before id
Error 129 error C4430: missing type specifier - int assumed
Error 130 error C4430: missing type specifier - int assumed
Warning 131 warning C4183: 'GetCanvasItems': missing return
Error 132 error C2146: syntax error : missing ';' before id
Error 133 error C4430: missing type specifier - int assumed
Error 134 error C4430: missing type specifier - int assumed
Error 135 error C2146: syntax error : missing ';' before id
Error 136 error C4430: missing type specifier - int assumed
Error 137 error C4430: missing type specifier - int assumed
Warning 138 warning C4183: 'GetCanvasItems': missing return
Error 139 error C2146: syntax error : missing ';' before id
Error 140 error C4430: missing type specifier - int assumed
Error 141 error C4430: missing type specifier - int assumed
Error 142 error C2146: syntax error : missing ';' before id
Error 143 error C4430: missing type specifier - int assumed
Error 144 error C4430: missing type specifier - int assumed
Error 145 error C2146: syntax error : missing ';' before id
Error 146 error C4430: missing type specifier - int assumed
Error 147 error C4430: missing type specifier - int assumed
Warning 148 warning C4183: 'GetScripts': missing return typ
Error 149 error C2146: syntax error : missing ';' before id
Error 150 error C4430: missing type specifier - int assumed
Error 151 error C4430: missing type specifier - int assumed
Warning 152 warning C4183: 'GetMailEnvelope': missing retur
Error 153 error C2146: syntax error : missing ';' before id
Error 154 error C4430: missing type specifier - int assumed
Error 155 error C2208: 'Excel::Scripts' : no members define
Error 156 fatal error C1903: unable to recover from previou





Re: Visual C++ General using excel type library in vc++2005

Ted.

You need all three #import commands, not just the one relating to excel.



Re: Visual C++ General using excel type library in vc++2005

ken9865432

Thanks for the tip.

I am new to ole/com automation. What I was doing was using visual studio's insert class (class wizard ) to automatically generate class (wrapper ) files. I also figured that there are two ways to do automation. The first way is using #import and other way by using class wizard. I was using class wizard to generate dispatch wrapper or whatever its called.

The class wizard inserted #import statements to the generated excel component file (such as "CApplication.h") but it seems like you have to delete all #import statements when you are using class wizard to do this. I deleted all #import statements and most errors disappeared and the program compiled.

Also vs2005 class wizard has a comfirmed bug that vs.net didnt have. 2005 fails to generate correct class name or somethi g. These inconvinience and differences between vstudio versions really makes things difficult for newbies like me.

Anyway I was able to start an excel application from c++. thats all I am able to do so far. I know that class wizard doesnt do everything for you but I am lacking in knowledge to figure out how to put things correct. Thanks for the help.





Re: Visual C++ General using excel type library in vc++2005

afung

I used the #import directive to import the excel library to make excel files but the excel object is not recognized by my application.


#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\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\OFFICE12\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")


I'm running VS 2005 and trying to open an excel document in Excel 2007. The code compiles properly with just the three #import directives, However, it returns compiler error when I added the follow code:

COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);


_Application app; // app is the Excel _Application object

// Start Excel and get Application object...
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't start Excel.");
}
else
{
//Make Excel Visible and display a message
app.SetVisible(TRUE);
AfxMessageBox ("Excel is Running!");
}

The error returned reads "error C2065: '_Application' : undeclared identifier"

What am I missing I have spend a while to trying to figure this out but no luck.

Thanks in advance.





Re: Visual C++ General using excel type library in vc++2005

Ted.

afung, you're mixing MFC style COM creation code with native COM. These two metaphors do not go together. you need to use something like this to create Excel object:

Excel::_ApplicationPtr application(__uuidof(Excel::Application));





Re: Visual C++ General using excel type library in vc++2005

afung

Thanks. This appears to be working... at least for certain files. The code below managed to open excel files saved in 2003 format, but it fails to open or recognize excel files saved in 2007 format. I current have Office 2007 installed on the development machine, and the import library is referenced to the "Office12" folder. Even the _tfindfirst function cannot find the file saved in 2007 format. What am I missing

Excel:_ApplicationPtr exlApp;

Excel:_WorkbookPtr exlWorkbook;

exlApp.CreateInstance( _T("Excel.Application")

_bstr_t bstrExcelFileName = _T("C:\\Data.xls");

_tfinddata_t stFileInfo;

TCHAR * pszExcelFileName = (TCHAR *)bstrExcelFileName;

if (_tfindfirst(pszExcelFileName, &stFileInfo) != -1){

// Open the Excel workboook.

exlWorkbook = exlApp->Workbooks->Open(bstrExcelFileName);

exlApp->put_Visible(0, false);

}

Thanks.





Re: Visual C++ General using excel type library in vc++2005

Ted.

The file extension is different for Excel 2007 files: it uses xlsx instead of xls. See:

http://technet2.microsoft.com/Office/en-us/library/e077da98-0216-45eb-b6a7-957f9c510a851033.mspx mfr=true