Handling ATL Control events in VB 
Author Message
 Handling ATL Control events in VB

Full ATL 3.0 windowed control is placed on VB6 form. The control contains
windows message handler for WM_LBUTTONDOWN that fires event to be handled in
VB code.

ATL:
----------------------------------------------------------------------------
LRESULT OnLButtonDown(UINT, WPARAM, LPARAM, BOOL&)
{
            Fire_Click();
            return 0;

Quote:
}

VB:
----------------------------------------------------------------------------
Sub MyCtrl_Click()
            Unload Me
End Sub

After getting back into the control from VB event handler the debug
assertion raised. Is it possible to correctly manage such kind of situation
in ATL architecture?



Fri, 06 Aug 2004 06:18:00 GMT  
 Handling ATL Control events in VB
There is a problem in the ATL windowing support - it assumes the instance
is valid after the message handler returns. Another step you need is to
stabilize the object lifetime by calling AddRef on yourself before fiing the
event and Release after that. This won't solve the windowing problem though.
A possible approach is to replace CWindowImpl with a template that performs
AddRef on its template parameter before each message handler and Release
when it's finished (or simply write it so as it doesn't access 'this' after the
message handler returns). I wrote such a replacement template class for
another problem with CWindowImpl - it crashes if you call DestroyWindow
within a message handler and "delete this;" in OnFinalMessage. It won't
help you as your problem is different, I just wanted to mention you are not
the only one to encounter the lack of thought in CWindowImpl's design...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> Full ATL 3.0 windowed control is placed on VB6 form. The control contains
> windows message handler for WM_LBUTTONDOWN that fires event to be handled in
> VB code.

> ATL:
> ----------------------------------------------------------------------------
> LRESULT OnLButtonDown(UINT, WPARAM, LPARAM, BOOL&)
> {
>             Fire_Click();
>             return 0;
> }

> VB:
> ----------------------------------------------------------------------------
> Sub MyCtrl_Click()
>             Unload Me
> End Sub

> After getting back into the control from VB event handler the debug
> assertion raised. Is it possible to correctly manage such kind of situation
> in ATL architecture?



Sun, 08 Aug 2004 08:51:35 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Events of Flex grid not being handled in ATL composite control

2. VB's mousepointer property not working when set from event of custom ATL control

3. ATL DLL event sink with a VB ActiveX DLL event source

4. VB Auto-generation of certain events (was Re: VB refuses to load my control DLL)

5. retrieve handle of the control from within the control when the container is vb

6. C# events handling vs VB

7. creating a sink in VC to handle events fired by VB Com Object

8. Handling VB COM Events in VC++ container

9. Handling Events From VB ActiveX exe

10. Message Handling - Controls - ATL Composite Controls

11. Event handling in ATL COM

12. Problem firing an event from ATL to VB which passes a SAFEARRAY

 

 
Powered by phpBB® Forum Software