Michael Lindig wrote a great article for firing Events using Visual
Studio 6 which works a treat. I have just compiled this under Visual
Studio 2005 and it crashes on the line :-
pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
I understand that many things have changed from VC6 to Visual Studio
2005, but I'm a little confused by this one. Has anyone had a similar
problem? Am I just better off using VC6 and forgetting about 2005?
Regards,
Chris
There's nothing wrong with this line by itself. Context is important. To
my shame, I have no idea who Michael Lindig is nor am I familiar with
his work. Why not provide a link to that article you are talking about?
--
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
The article is on CodeGuru at
http://www.codeguru.com/cpp/com-tech/atl/atl/article.php/c75/
All I did was download the sample, convert and compile it under Visual
Studio 2005 and it crashes. This code compiles and works under Visual
Studio 6.
Regards,
Chris
Implementation of CComDynamicUnkArray has changed.
CComDynamicUnkArray_GIT relies on implementation details.
It used to be in VC6 that CComDynamicUnkArray::Add(IUnknown*) returned
IUnknown* pointer itself, cast to a DWORD. In VC7 and up this has
changed - what's returned is an index into the array of pointers. The
change is probably due to the fact that casting pointers to DWORDs is
not such a smart move on 64bit.
CComDynamicUnkArray_GIT however assumes VC6 implementation. In
particular, CComDynamicUnkArray_GIT::GetAt calls
CComDynamicUnkArray::GetAt, casts the returned IUnknown* pointer to a
DWORD and assumes it's the same DWORD that was earlier returned by
CComDynamicUnkArray::Add, which it's not. Not finding the cookie in its
internal map, it casts the DWORD back to IUnknown* and returns that.
This is the original, unmarshalled IUnknown, so we are back to precisely
the same problem we started with.
I've answered my own question. It turns out that the Threading Model
was set to "Both" instead of "Free". When I changed it to "Free" by
editing the rgs file it worked ok. Interesting that it worked on Visual
Studio 6 and not on Visual Studio 2005. I'm guessing that 2005 has more
error handling and is not as fault tolerant.
Regards,
Chris
No. When you set your threading model to Free, your worker thread is in
the _same_ apartment as the thread your object is created in (MTA). The
whole issue of marshalling the sink pointer between main and worker
threads fails to arise: the sink pointer is automatically marshalled at
the time IConnectionPoint::Advise is called (since this call itself is
already cross-apartment).
If you want your object to be Free-threaded, you don't need this whole
GIT dance at all. Just lose it.