Click here to Skip to main content
15,897,315 members
Home / Discussions / COM
   

COM

 
GeneralATL / COM question Pin
__makaveli__7-Jan-05 0:24
__makaveli__7-Jan-05 0:24 
GeneralRe: ATL / COM question Pin
Lim Bio Liong7-Jan-05 6:07
Lim Bio Liong7-Jan-05 6:07 
GeneralRe: ATL / COM question Pin
__makaveli__9-Jan-05 22:05
__makaveli__9-Jan-05 22:05 
GeneralRe: ATL / COM question Pin
Martin Koorts9-Jan-05 22:44
Martin Koorts9-Jan-05 22:44 
GeneralRe: ATL / COM question Pin
__makaveli__9-Jan-05 23:32
__makaveli__9-Jan-05 23:32 
GeneralRe: ATL / COM question Pin
Martin Koorts10-Jan-05 1:03
Martin Koorts10-Jan-05 1:03 
GeneralRe: ATL / COM question Pin
__makaveli__10-Jan-05 1:09
__makaveli__10-Jan-05 1:09 
GeneralRe: ATL / COM question Pin
Martin Koorts10-Jan-05 3:33
Martin Koorts10-Jan-05 3:33 
Hi
The following bit of code demonstrates what is possible with ATL and catching events from the MS Calendar ActiveX control;

<<<<<<<<< START OF CODE >>>>>>>>>>
// main.cpp
#define _WIN32_WINNT 0x0500 // if you want to use ::CoInitializeEx
#include <atlbase.h>
#include <atlcom.h>


#import "C:\Program Files\Microsoft Office\OFFICE11\mscal.ocx" \
rename_namespace("cal") \
raw_interfaces_only


const int CALENDAR_SOURCE_ID = 0;

class CMyCalendarEvents;

typedef IDispEventSimpleImpl<calendar_source_id, cmycalendarevents,="" &__uuidof(cal::dcalendarevents)="">
CalendarEventsImpl;

_ATL_FUNC_INFO OnNewMonthInfo = { CC_STDCALL, VT_EMPTY, 0, 0 };

class CMyCalendarEvents
: public CalendarEventsImpl
{
public:
BEGIN_SINK_MAP(CMyCalendarEvents)
SINK_ENTRY_INFO(CALENDAR_SOURCE_ID, __uuidof(cal::DCalendarEvents), 1, OnNewMonth, &OnNewMonthInfo)
END_SINK_MAP()

void __stdcall OnNewMonth()
{
_RPT0(_CRT_WARN, "## Month Changed!\n");
}
};


void main()
{
if (FAILED(::CoInitialize(0)))
return;

try
{
CMyCalendarEvents ce;

CComPtr<cal::icalendar> ptrCalendar;
HRESULT hr = ptrCalendar.CoCreateInstance(OLESTR("MSCAL.Calendar"));
_com_util::CheckError(hr);

// start listening
hr = ce.DispEventAdvise(ptrCalendar, &__uuidof(cal::DCalendarEvents));
_com_util::CheckError(hr);

hr = ptrCalendar->Today(); // OnNewMonth fires ??
_com_util::CheckError(hr);

hr = ptrCalendar->Today(); // OnNewMonth fires ??
_com_util::CheckError(hr);

// stop listening
hr = ce.DispEventUnadvise(ptrCalendar, &__uuidof(cal::DCalendarEvents));
_com_util::CheckError(hr);

hr = ptrCalendar->Today(); // OnNewMonth fires ??
_com_util::CheckError(hr);
}
catch (...)
{
// do nothing
}

::CoUninitialize();
}
<<<<<<<<< END OF CODE >>>>>>>>>>


In your case, the event sink would look different, for example, the IReportEvent::NoData handler would be (I think);


<<<<<<<<< START OF CODE >>>>>>>>>>
const int REPORT_SOURCE_ID = 0;

class CMyReportEvents;

typedef IDispEventSimpleImpl<report_source_id, cmyreportevents,="" &__uuidof(cr::ireportevent)="">
ReportEventsImpl;

_ATL_FUNC_INFO OnNoDataInfo = { CC_STDCALL, VT_EMPTY, 1, { VT_PTR | VT_BOOL } };

class CMyReportEvents
: public ReportEventsImpl
{
public:
BEGIN_SINK_MAP(CMyReportEvents)
SINK_ENTRY_INFO(REPORT_SOURCE_ID, __uuidof(cr::IReportEvent), 1, OnNoData, &OnNoDataInfo)
END_SINK_MAP()

void __stdcall OnNoData(VARIANT_BOOL *pCancel)
{
_ASSERT(false);
}
};
<<<<<<<<< END OF CODE >>>>>>>>>>

HTH
Martin
GeneralRe: ATL / COM question Pin
__makaveli__10-Jan-05 4:54
__makaveli__10-Jan-05 4:54 
GeneralRe: ATL / COM question Pin
Martin Koorts10-Jan-05 5:58
Martin Koorts10-Jan-05 5:58 
GeneralRe: ATL / COM question Pin
__makaveli__10-Jan-05 22:16
__makaveli__10-Jan-05 22:16 
GeneralRe: ATL / COM question Pin
__makaveli__10-Jan-05 22:39
__makaveli__10-Jan-05 22:39 
GeneralRe: ATL / COM question Pin
Martin Koorts10-Jan-05 23:06
Martin Koorts10-Jan-05 23:06 
GeneralThe OLE clipboard and Word 2003 Pin
Steve DeLassus6-Jan-05 7:27
Steve DeLassus6-Jan-05 7:27 
GeneralActiveX VBScripting problem Pin
mdave5-Jan-05 7:58
mdave5-Jan-05 7:58 
GeneralInterface Discovery - Modification Pin
KragAapie4-Jan-05 19:01
KragAapie4-Jan-05 19:01 
GeneralRe: Interface Discovery - Modification Pin
Martin Koorts9-Jan-05 22:19
Martin Koorts9-Jan-05 22:19 
GeneralRe: Interface Discovery - Modification Pin
geo_m16-Jan-05 20:58
geo_m16-Jan-05 20:58 
GeneralHelp in creating Arrow OCX Pin
Surya Prakash Adari4-Jan-05 18:09
Surya Prakash Adari4-Jan-05 18:09 
GeneralCreating threads in VB6 Activex DLL Pin
K.Sandeep4-Jan-05 0:32
K.Sandeep4-Jan-05 0:32 
GeneralRemoving the type library from a DLL Pin
Shutter3-Jan-05 15:47
Shutter3-Jan-05 15:47 
GeneralRe: Removing the type library from a DLL Pin
FearlessBurner4-Jan-05 10:34
FearlessBurner4-Jan-05 10:34 
GeneralRe: Removing the type library from a DLL Pin
Shutter4-Jan-05 11:39
Shutter4-Jan-05 11:39 
GeneralRe: Removing the type library from a DLL Pin
ThatsAlok4-Jan-05 17:25
ThatsAlok4-Jan-05 17:25 
GeneralRe: Removing the type library from a DLL Pin
FearlessBurner5-Jan-05 6:20
FearlessBurner5-Jan-05 6:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.