KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The Question My question is: Does C# nativly support late-binding IDispatch? Pretend i'm trying to automate Office, while being compatible with whatever version the customer has installed. In the .NET world if you developed with Office 2000 installed, every developer, and every customer, from now until the end of time, is required to have Office 2000. In the world before .NET, we used COM to talk to Office applications. For example: 1) Use the version independant ProgID "Excel.Application" which resolves to: clsid = {00024500-0000-0000-C000-000000000046} and then using COM, we ask for one of these classes to be instantiated into an object: IUnknown unk; CoCreateInstance( clsid, null, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IUnknown, out unk); And now we're off to the races - able to use Excel from inside my application. Of course, if really you want to use the object, you have to call have some way of calling methods. We could get ahold of the various interface declarations, translated into our language. This technique is good because we get early binding code-insight compile type syntax checking and some example code might be: Application xl = (IExcelApplication)unk; ExcelWorkbook workbook = xl.Workbooks.Add(template, lcid); Worksheet worksheet = workbook.ActiveSheet; But there is a downside of using interfaces: we have to get ahold of the various interface declarations, transated into our language. And we're stuck using method-based invocations, having to specify all parameters, e.g.: ExcelWorkbook workbook = xl.Workbooks.Add(template, lcid); xl.Worksheets.Add(before, after, count, ty
Tags (comma-separated)
Save Edits
Cancel