Thursday, March 09, 2006 4:59 PM
Rinat Shagisultanov
.NET event, VC6 sink, problems with event parameters
I recently had a problem in the COM Interop when you try to use event sink with parameter of enumeration type exposed to VC++ 6.0 ATL. This event sink is working perfectly well with VB6, but not with VC++ 6.0.
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 debugger:
"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"
The investigation resulted in the discovery of the bug in ATL that Microsoft will not fix :-). But here is a description and workaround to make it working
BUG: IDispEventImpl Event Handlers May Give Strange Values for Parameters
http://support.microsoft.com/?id=241810
FIX: Events Fail in ATL Containers when Enum Used as Event Parameter
http://support.microsoft.com/?id=237771 - This fix worked!
BUG: ATL Events Don't Fire If Defined With Interface Alias
http://support.microsoft.com/?id=244204