tags:

views:

508

answers:

4

I am writing an background service application that has to automatically read data from Excel 2003 files. But no matter what I try, the method OlePropertyGet() always results in an EAccessViolation error while trying to read from address "00000800".

The error always occurs at the last line of this code snippet, and seems independent of what parameter the method receives:

Variant excel, workbooks;

try
{
    excel = GetActiveOleObject("Excel.Application");
}
catch(...)
{
    excel = CreateOleObject("Excel.Application");
}

workbooks = excel.OlePropertyGet("Workbooks");

I've done some extensive google search on this, but found nothing that's even remotely helpful, only this forum thread where someone has the same issue, but doesn't give any information about the cause or solution (it's somewhat funny that at one point the author mentions he knows the cause, but doesn't say what it is!).

I'm open to any ideas as to what is causing this and how to solve this problem, but also alternative approaches to Excel OLE automation.

A: 

You can use Visual Studio Tools for Office (see http://msdn.microsoft.com/en-us/library/d2tx7z6d.aspx).

Or you can use ATL support to instantiate the object model provided by office.

Cătălin Pitiș
A: 

Oh, sorry, I forgot to mention, I am using CBuilder 6. Besides, that link you provided explicitly states the tools are for Visual Basic and C#, so no help here anway.

Thanks anyway. ;)

+1  A: 

my guess is its a null pointer issue..

it looks like neither GetActiveOleObject() nor CreateOleObject() worked

try checkign the validity of 'excel' before calling OlePropertyGet

an i guess you should make sure you have excel installed

ShoeLace
A: 

Your code may not be able to resolve "Excel.Application" successfully, leading to a null pointer. It uses a registry lookup with that string to identify Excel. It sounds like you're missing that registry entry.

Greg