I am trying to modify the EventSinkMap of an ActiveX control at runtime. I need a different function to be called when a certain event occurs (ie data received from a serial port).
After delving into MFC I have found several functions that will allow you to get to the EventSinkMap and its entries;
AFX_EVENTSINKMAP* pSinkMap = (AFX_EVENTSINKMAP *)GetEventSinkMap();
pEntry = (AFX_EVENTSINKMAP_ENTRY *)pSinkMap->lpEntries;
while (pEntry->dispEntry.nPropOffset != -1)
if (pEntry->dispEntry.lDispID == someID)
((*pEntry).dispEntry).pfn = (AFX_PMSG)SomeFunction;
The problem is I keep getting an access violation at the '.pfn =' statement.
I have also tried the following with the same results;
pEntry->dispEntry.pfn = (AFX_PMSG)SomeFunction;
SomeFunction has been declared as the same type and return value as the one I am trying to replace.
Is it not possible to modify these values at runtime? Or is there a simpiler solution that I am missing.