Re: can event handler call event source passed as connection point parameter?
What's weird here is that if I do a redundant QueryInterface on the
pointer for its own type, the code runs normal! The code is similar to
following:
// event source in free threaded DLL
class CServer ... {
Fire_OnSomeEvent(IServer* ptr) { // ATL generated
...
HRESULT hr = Invoke(...);
...
}
SomeMethod() {}
};
// event handler in apartment threaded EXE
class CClient ... {
void __stdcall OnSomeEvent(IServer * ptr) {
ptr->QueryInterface(IID_IServer, (void**)&ptr); // line X
ptr->SomeMethod(): // line Y
}
};
With line X, everything works fine and line Y does call through
SomeMethod().
Without line X, I saw "0x0000005 access violation while writing" at
line Y if I turned on all exception for debugging, and the Invoke in
the Fire method returned 0x80010105.
Is this related to the threading issue? Any idea why line X workaround
the problem?
Thanks & regards,
Xudong
Igor Tandetnik wrote:
chenxudongsg@gmail.com wrote:
If event source passes itself as parameter with Fire_OnSomeEvent(...),
can event handler OnSomeEvent(...) invokes its methods via the pointer
passed in?
Yes.
I tried that but received error "0x80010105 The server
threw an exception" inside Fire_OnSomeEvent(...) at the time event
handler made such call.
You did something wrong: either the server or the client crashed for
some reason. There is no fundamental underlying problem with what you
are trying to do - there's a bug in your code somewhere.
--
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