I have found that when I add new events to an existing COM/IDL interface, I sometimes run into strange issues unless they are added to the end of the interface.
For example, say I have the following interface:
interface IMyEvents
{
HRESULT FooCallback(
[in] long MyParam1,
[in] long MyParam2,
[in] long MyParam3);
HRESULT BarCallback(
[in] long MyParam1,
[in] BSTR MyParam2,
[in] BSTR MyParam3);
};
Now let's say I want to add a new callback event, NewCallback
. If I add it like this, I tend not to have any problems when the event is fired across COM:
interface IMyEvents
{
HRESULT FooCallback(
[in] long MyParam1,
[in] long MyParam2,
[in] long MyParam3);
HRESULT BarCallback(
[in] long MyParam1,
[in] BSTR MyParam2,
[in] BSTR MyParam3);
/* New event added to the end */
HRESULT NewCallback(
[in] BSTR MyParam1,
[in] BSTR MyParam2,
[in] BSTR MyParam3);
};
But if I add it like this, I can run into all sorts of problems (e.g. buffer overruns) when the event is fired.
interface IMyEvents
{
HRESULT FooCallback(
[in] long MyParam1,
[in] long MyParam2,
[in] long MyParam3);
/* New event added to the middle */
HRESULT NewCallback(
[in] BSTR MyParam1,
[in] BSTR MyParam2,
[in] BSTR MyParam3);
HRESULT BarCallback(
[in] long MyParam1,
[in] BSTR MyParam2,
[in] BSTR MyParam3);
};
I'm guessing it has something to do with DLL entry points, address offsets, or something similar. Or maybe it's because I haven't re-built something properly, and adding it to the end allows it to work by sheer luck.
Can anyone explain this behaviour?