.NET event, VC6 sink, problems with event parameters

.NET event, VC6 sink, problems with event parameters

Post by Eric Brand » Sat, 27 Sep 2003 00:35:49


Hi-

We have some .NET code that generates an event. The 2nd parameter of the
event is a C# class we derived from EventArgs.

A VC6 C++ client is subscribing to the event, we are using the
IDispEventImpl<> template in ATL, and have specified the
ComSourceInterfacesAttribute on our event generating class, as well as the
InterfaceTypeAttribute(InterfaceIsIDispatch) on our dummy interface for the
event in C#.

We are getting the callback made into C++ with no problem. The problem
occurs when we try to call a method of our EventArgs-derived parameter to
the event callback. When we make a call to say,
get_Name(&bstr); on our EventArgs-derived class in the C++ callback ('Name'
is a property in our EventArgs derived class) we get the following error
from the VC6 de *** :

"The value of ESP was not properly saved across a function call. This is
usually the result of calling a function declared with one calling
convention with a function pointer declared with a different calling
convention"

I have tried various settings in Project->Settings->C++->Code
Generation->Calling Convention, with no differences in behavior.

When our test app is in VB6 instead of VC6, we can access the parameters's
methods/properties with no problesm from within the event's callback
function.

Another note, when we implemented this event as a dual interface, and
received it in VC++ via a custom interface (rather than IDispatch), I am
pretty sure we were able to access the parameters methods and properties
with out the above crash. the problem, of course, is that with our COM
interface declared as Dual rather than IDispatch, we were unable to receive
the event in VB6.

Sorry for the long post, but there's no easy way to describe the problem.
Can anybody pinpoint what we are doing wrong so that we can access the event
parameters from C++?

Thanks in advance,
Eric.
 
 
 

.NET event, VC6 sink, problems with event parameters

Post by Vadim Meln » Sat, 27 Sep 2003 03:36:12

Hi,

the

What if you provide C# interface members with DispIdAttribute, will it help?

('Name'

Also some articles to check, it may be ATL's 3.0 IDispEventImpl problem...

BUG: IDispEventImpl Event Handlers May Give Strange Values for Parameters
http://www.yqcomputer.com/

FIX: Events Fail in ATL Containers when Enum Used as Event Parameter
http://www.yqcomputer.com/

BUG: ATL Events Don't Fire If Defined With Interface Alias
http://www.yqcomputer.com/

..
Thanks,
Vadim.

 
 
 

.NET event, VC6 sink, problems with event parameters

Post by Eric Brand » Sat, 27 Sep 2003 22:50:35

Vadim & group,
Thanks for your advice.
We figured out how to make it work but don't really understand the reason.
Perhaps someone could explain if they know....

We changed the 2 parameters in the C++ callback function (of IDispEventImp)
from the interface types that they really were to IDispatch*. Then inside
the function, we QI'ed the IDispatch pointers for the real interface pointer
we knew the parameter was. Then, accessing methods and properties of that
interface was successful.

Also, BTW, this was done over a local server (i.e., two separate exes). I
believe things worked fine when were were inproc.

Thanks,
E.

To get it to work, we changed both the parameters in the C++ implementation
of our event callback to


the
help?
to