Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel iDispatch problem

I have code like this:

IConnectionPoint *pCPSheetEvents, *pCPAppEvents;
CExcelEventSink Sink;
DWORD dwSheetEventsCookie, dwAppEventsCookie;
BOOL bDocSinkInPlace = FALSE, bAppSinkInPlace = FALSE;
BOOL __stdcall xlAutoOpen(void) {
connect();
CLSID clsid;
CLSIDFromProgID(L"Excel.Application", &clsid);
IUnknown *pUnk = NULL;
bool jest = false;
HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
if(SUCCEEDED(hr)){
hr = pUnk-QueryInterface(IID_IDispatch, (void **)&pDisp);
if(!pDisp)
::MessageBox(NULL, "Failed to find instance!!", "Error",
MB_ICONHAND);
else{
::MessageBox(NULL, "Got instance of Excel!", "Success", MB_OK);
jest = true;
}
if (pUnk)
pUnk-Release();
}
else{
::MessageBox(NULL, "No active object of Excel!", "Success", MB_ICONHAND);
}

If user clicks on Excels xls file, Excel is run with active object - this is correct way for my use. But if user starts Excel by executing program file, Excel opens with NO workbook, and my connection is not established. Is there any clue to tell Excel that it should expose to me its EventSink and register my OnWorkbookOpen slot for my function? Or maybe you know how to tell Excel that my function written in C++ as xll should not be volatile but should recalculate all the fields in workbook on workbook open event? Its a function retrieving results from an SQL database, so my boss told me, its useless if the data is saved data, and not fresh grabbed by SQL query.

Anybody help?
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Error Message: NULL IDispatch passed to Autowrap() Aviral Sharma Excel Discussion (Misc queries) 0 March 13th 09 05:13 AM
Exit from Excel edit mode using IDispatch Goofball Excel Discussion (Misc queries) 8 November 23rd 07 09:46 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
different IDispatch in event handler Dirk[_2_] Excel Programming 0 January 23rd 04 11:04 PM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"