ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel iDispatch problem (https://www.excelbanter.com/excel-programming/302869-excel-idispatch-problem.html)

Excel iDispatch problem

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?


All times are GMT +1. The time now is 08:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com