The error that I got is: error C2039: "OnTrigger": is not a member of
'ICTIXEvents'
I have follow a step by step process to add this event to the
component
1. Add the dispinterface to the IDL
2. Add the event method to this interface
3. Add the dispinterface to the coclass specifying [default, source]
4. Compile the IDL
5. Add a connection Point To The Class
which generates the right entries for the class
public IConnectionPointContainerImpl<CCTIX>,
public CProxyICTIXEvents<CCTIX>,
on the com map
COM_INTERFACE_ENTRY(IConnectionPointContainer)
and on the Connection Point Map
CONNECTION_POINT_ENTRY(__uuidof(ICTIXEvents))
and generates the Fire_OnTrigger() method in the CProxyICTIXEvents
class
6. I have added the code to call fire this event.
However when compiling I get the error I previously mentioned.
However in the IDL the dispinterface for ICTIXEvents is defined as
[
uuid(002B6D0B-0D81-46FC-AE17-597728C721AA),
version(1.0)
]
dispinterface ICTIXEvents
{
properties:
methods:
[id(0x000000c9)] void OnTrigger( [in] short Line, [in]
EventTypes EventType);
};
However the Generated file CTIXControl1.h that contains the generated
definition of the interface does not show this method
MIDL_INTERFACE("002B6D0B-0D81-46FC-AE17-597728C721AA")
ICTIXEvents: public IDispatch
{
};
There seems to be an disconnect between the IDL and the Interface
generated by MIDL that is stopping studio from compiling. I have spent
a great deal of time researching on the Internet but I have not be
able to find a hint to why this is happening.
Thanks in advance for any help.
Show the code that calls OnTrigger. Was it generated by the wizard? For
a dispinterface, the wizard should have generated a call to
IDispatch::Invoke instead.
> However the Generated file CTIXControl1.h that contains the generated
> definition of the interface does not show this method
>
> MIDL_INTERFACE("002B6D0B-0D81-46FC-AE17-597728C721AA")
> ICTIXEvents: public IDispatch
> {
> };
This is normal for a dispinterface. Dispinterface methods are not real
methods, they are simply contracts on what DISPIDs are valid for
IDispatch::Invoke call and what parameters should accompany each DISPID.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Thanks very much Igor,
That is good to know, however the compiler is complaining that the
onTriger() does not exist on that interface.
The offending line is hr = pConnection->OnTrigger( Line, EventType);
which is located in the Fire_onTrigger method from the
CProxyICTIEvents class, and this method was generated by the "add
connection point" wizard from Visual Studio.
HRESULT Fire_OnTrigger( short Line, TxEventTypes EventType)
{
HRESULT hr = S_OK;
T * pThis = static_cast<T *>(this);
int cConnections = m_vec.GetSize();
for (int iConnection = 0; iConnection < cConnections; iConnection++)
{
pThis->Lock();
CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
pThis->Unlock();
ICTIXEvents * pConnection = static_cast<ICTIXEvents
*>(punkConnection.p);
if (pConnection)
{
hr = pConnection->OnTrigger(Line, EventType); // <-------
offending line.
}
}
return hr;
}
I'm really confused now since you said that it is normal for the
dispinterface to be be empty. do you know what could be causing this?
Thanks,
Of course. That's precisely what I was saying.
> The offending line is hr = pConnection->OnTrigger( Line, EventType);
> which is located in the Fire_onTrigger method from the
> CProxyICTIEvents class, and this method was generated by the "add
> connection point" wizard from Visual Studio.
The code is written as if for a regular interface, not a dispinterface.
Did you make ICTIXEvents a regular interface originally, generated the
connection point proxy, then changed it to a dispinterface? Try
recreating the proxy (simply do Implement Connection Point again).
Thanks very much Igor!!!! that solved the compilation problem.
It seems that when I was starting the project I implemented both
interfaces and that included entries in the COM MAP for the
ICTIXEvents Interface. What I did was remove this from the COM map and
remove all previous entries generated by the "add connection Point"
wizard also I deleted the code for the Fire_OnTrigger event. Then I
added the connection point again and at last the compiler issue went
away.
Thanks again for your advise.
I have another problem in that the connection point wizard seems to be using an older version of my type library to generated the connection point. Anybody have insights into how to resolve this.
wilmero wrote:
Re: ATL Compiler Error When Adding Events
03-May-08
EggHeadCafe - Software Developer Portal of Choice
BOOK REVIEW: Professional Silverlight 2 for ASP.NET Developers [WROX]
http://www.eggheadcafe.com/tutorials/aspnet/3573070a-b0b0-49e5-99c8-cddc274ec7f8/book-review-professional.aspx