Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visual Studio 2005 - Firing Events from a Worker Thread

37 views
Skip to first unread message

Chris

unread,
Jan 1, 2007, 1:49:04 AM1/1/07
to
Hi All,


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

Igor Tandetnik

unread,
Jan 1, 2007, 10:49:52 AM1/1/07
to
"Chris" <ch...@scadaengine.com> wrote in message
news:1167634144.5...@v33g2000cwv.googlegroups.com

> 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);

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


Chris

unread,
Jan 1, 2007, 3:29:06 PM1/1/07
to
Sorry, I should have provided more information.

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

Igor Tandetnik

unread,
Jan 1, 2007, 6:30:48 PM1/1/07
to
"Chris" <ch...@scadaengine.com> wrote in message
news:1167683346....@42g2000cwt.googlegroups.com

> Sorry, I should have provided more information.
>
> 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.

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.

Chris

unread,
Jan 1, 2007, 6:36:39 PM1/1/07
to
Hi Igor,

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

Igor Tandetnik

unread,
Jan 1, 2007, 6:52:08 PM1/1/07
to
"Chris" <ch...@scadaengine.com> wrote in message
news:1167694599.6...@v33g2000cwv.googlegroups.com

> 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.

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.

0 new messages