Click here to Skip to main content
15,911,360 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
AnswerRe: how des "GetSize().foo = NULL" work Pin
Jörgen Sigvardsson31-Dec-04 14:13
Jörgen Sigvardsson31-Dec-04 14:13 
GeneralRe: how des "GetSize().foo = NULL" work Pin
dcudev.lcr4-Jan-05 4:53
dcudev.lcr4-Jan-05 4:53 
GeneralRe: how des "GetSize().foo = NULL" work Pin
Jörgen Sigvardsson4-Jan-05 8:27
Jörgen Sigvardsson4-Jan-05 8:27 
QuestionWhy this can`t compler? Pin
anycallmy30-Dec-04 15:07
anycallmy30-Dec-04 15:07 
AnswerRe: Why this can`t compler? Pin
Michael Dunn30-Dec-04 19:39
sitebuilderMichael Dunn30-Dec-04 19:39 
GeneralRe: Why this can`t compler? Pin
anycallmy3-Jan-05 18:55
anycallmy3-Jan-05 18:55 
GeneralVB crash Pin
De Nardis Andrea30-Dec-04 1:11
De Nardis Andrea30-Dec-04 1:11 
GeneralRe: VB crash Pin
Anonymous30-Dec-04 3:32
Anonymous30-Dec-04 3:32 
In short : The interface pointer used by your worker thread to fire the events is not valid for the worker thread.

In length (there are numerous resources on the web that discusses this problem):
http://www.mvps.org/vcfaq/com/1.htm[^]

It's doesn't matter that the object is martked 'Both'. VB instansiates it in an STA.

In detail: When you fire the event in your worker thread that thread executes native VB code. VB assumues that the thread that calls it is always the same thread (the same requirement as for the STA). VB tries to get data in the TLS but since it is the wrong thread that calls VB, VB will sometimes throw access violation (if you're lucky).

If the object would've been marked 'Free' (an MTA object) then VB (or rather the COM-runtime) is forced to instansiate the COM object in the MTA. If the worker thread then also enters the MTA (by calling CoInitializeEx with argument COINIT_MULTITHREADED) then it's legal for the worker thread to fire the events in the way the VC 6 wizard generates the event-firing code. In this case COM will automatically put up proxy/stub pairs between the VB and your object ensuring that it's the correct thread that calls the VB code.

The drawbacks are:
1. Performance (every call is marshalled and will force a thread switch, few calls = no problem, many calls = large performance hit)
2. You must secure your object for concurrent access (but since it was marked 'Both' it should've been secure already
3. An MTA object _can not_ be an ActiveX object (that is a COM object with UI)

A peculiar detail is:
1. When the VB code calls your object the COM runtime will pump the message loop.
GeneralAll frames, redirecting Pin
Anonymous29-Dec-04 13:38
Anonymous29-Dec-04 13:38 
GeneralRe: All frames, redirecting Pin
Michael Dunn29-Dec-04 13:59
sitebuilderMichael Dunn29-Dec-04 13:59 
GeneralRe: All frames, redirecting Pin
Gerald Schwab29-Dec-04 14:06
Gerald Schwab29-Dec-04 14:06 
GeneralRe: All frames, redirecting Pin
Anonymous30-Dec-04 0:37
Anonymous30-Dec-04 0:37 
GeneralRe: All frames, redirecting Pin
Arun Chembilath30-Apr-11 6:06
Arun Chembilath30-Apr-11 6:06 
GeneralRe: how to call a dialog box from outlook express button Pin
ThatsAlok30-Dec-04 18:32
ThatsAlok30-Dec-04 18:32 
GeneralRe: how to call a dialog box from outlook express button Pin
ThatsAlok30-Dec-04 19:47
ThatsAlok30-Dec-04 19:47 
GeneralMFC to ATL ActiveX port troubles Pin
greekgoddj27-Dec-04 22:06
greekgoddj27-Dec-04 22:06 
GeneralIHTMLWindow2::execScript() reports error "Invalid class string" Pin
Paul_buaa27-Dec-04 20:11
Paul_buaa27-Dec-04 20:11 
GeneralRe: IHTMLWindow2::execScript() reports error "Invalid class string" Pin
Vi229-Dec-04 22:12
Vi229-Dec-04 22:12 
GeneralIE Add-on and translate page Pin
Samsung24-Dec-04 16:15
Samsung24-Dec-04 16:15 
GeneralHelp me with OLE error ( RPC_E_CANTCALLOUT_ININPUTSYNCCALL ) Pin
User 21559723-Dec-04 5:12
User 21559723-Dec-04 5:12 
GeneralRe: Help me with OLE error ( RPC_E_CANTCALLOUT_ININPUTSYNCCALL ) Pin
Jörgen Sigvardsson23-Dec-04 7:00
Jörgen Sigvardsson23-Dec-04 7:00 
GeneralRe: Help me with OLE error ( RPC_E_CANTCALLOUT_ININPUTSYNCCALL ) Pin
User 21559723-Dec-04 22:22
User 21559723-Dec-04 22:22 
GeneralWrong vector ctor used with iterator Pin
Johann Gerell21-Dec-04 20:03
Johann Gerell21-Dec-04 20:03 
GeneralRe: Wrong vector ctor used with iterator Pin
Stuart Dootson21-Dec-04 22:19
professionalStuart Dootson21-Dec-04 22:19 
GeneralRe: Wrong vector ctor used with iterator Pin
Johann Gerell22-Dec-04 0:32
Johann Gerell22-Dec-04 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.