How To Handle COM Events 
Author Message
 How To Handle COM Events

Hi Folks -

I am using VB6 to build a Standard EXE that will run
in unattended execution mode (no forms in the project).
I have a 3rd party OCX that I need to instantiate
in code using CreateObject() and then call its
methods.

This all works fine, but the OCX generates an event
when it's done doing its work, and I need to have
my program handle the event or all is lost.  I tried
using the "Implements" statement in the declarations
area of my main module, but I get an error from the
IDE.  Can one of you VB experts give me a quick
rundown as to how I can make this EXE handle the
events generated by this OCX?

I have a hunch that this will involve creating
a class module, using Implements in the class, and
instantiating the OCX in the Class_Initialize event
of the class.  Am I right?

PLEASE respond via e-mail, also. Thanks in advance
for the pointers.

--
Morgan Leppink, EquiSoft

MCSE, MCP+I

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Thu, 01 May 2003 11:38:42 GMT  
 How To Handle COM Events
Have you tried withevents?
private withevents OCXobject as ThirdpartyOCX
set OCXobject = createobject(...)

private sub OCXobject_event1(par1 as par1def)
call process_OCXevent
end sub

Quote:

> Hi Folks -

> I am using VB6 to build a Standard EXE that will run
> in unattended execution mode (no forms in the project).
> I have a 3rd party OCX that I need to instantiate
> in code using CreateObject() and then call its
> methods.

> This all works fine, but the OCX generates an event
> when it's done doing its work, and I need to have
> my program handle the event or all is lost.  I tried
> using the "Implements" statement in the declarations
> area of my main module, but I get an error from the
> IDE.  Can one of you VB experts give me a quick
> rundown as to how I can make this EXE handle the
> events generated by this OCX?

> I have a hunch that this will involve creating
> a class module, using Implements in the class, and
> instantiating the OCX in the Class_Initialize event
> of the class.  Am I right?

> PLEASE respond via e-mail, also. Thanks in advance
> for the pointers.

> --
> Morgan Leppink, EquiSoft

> MCSE, MCP+I

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 How To Handle COM Events
Fedor -

It does look like WithEvents is the key.  But,
I will still need to wrap my 3rd party OCX in
a VB calss, right?  The documentation says that
WithEvents is not valid in a standard module.

Thanks,

- Morgan


Quote:

> Have you tried withevents?
> private withevents OCXobject as ThirdpartyOCX
> set OCXobject = createobject(...)

> private sub OCXobject_event1(par1 as par1def)
> call process_OCXevent
> end sub


> > Hi Folks -

> > I am using VB6 to build a Standard EXE that will run
> > in unattended execution mode (no forms in the project).
> > I have a 3rd party OCX that I need to instantiate
> > in code using CreateObject() and then call its
> > methods.

> > This all works fine, but the OCX generates an event
> > when it's done doing its work, and I need to have
> > my program handle the event or all is lost.  I tried
> > using the "Implements" statement in the declarations
> > area of my main module, but I get an error from the
> > IDE.  Can one of you VB experts give me a quick
> > rundown as to how I can make this EXE handle the
> > events generated by this OCX?

> > I have a hunch that this will involve creating
> > a class module, using Implements in the class, and
> > instantiating the OCX in the Class_Initialize event
> > of the class.  Am I right?

> > PLEASE respond via e-mail, also. Thanks in advance
> > for the pointers.

> > --
> > Morgan Leppink, EquiSoft

> > MCSE, MCP+I

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

--
Morgan Leppink, EquiSoft
MCSE, MCP+I

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 How To Handle COM Events
Hi!
Absolutely correct, You need to construct some class and put withevents
variable inside one.
As You have no forms, You need some class.

class module:
option explicit
private withevents OCXobject as ThirdpartyOCX

private sub class_initialize()
on error goto errhandler

set OCXobject = createobject(...)
exit sub
errhandler

err.raise blablabla

end sub

private sub OCXobject_event1(par1 as par1def)
call process_OCXevent
end sub

private sub class_terminate
on error goto errhandle
set OCXobject = nothing
exit sub
errhandle:
end sub
private sub process_OCXevent()
end sub

in standard module:

option explicit
private mClass as MyClass

sub main

set mClass = new myClass

"here You need to put something to keep mClass alive after exit sub or
don't exit sub main at all

exit sub

Quote:

> Fedor -

> It does look like WithEvents is the key.  But,
> I will still need to wrap my 3rd party OCX in
> a VB calss, right?  The documentation says that
> WithEvents is not valid in a standard module.

> Thanks,

> - Morgan



> > Have you tried withevents?
> > private withevents OCXobject as ThirdpartyOCX
> > set OCXobject = createobject(...)

> > private sub OCXobject_event1(par1 as par1def)
> > call process_OCXevent
> > end sub


> > > Hi Folks -

> > > I am using VB6 to build a Standard EXE that will run
> > > in unattended execution mode (no forms in the project).
> > > I have a 3rd party OCX that I need to instantiate
> > > in code using CreateObject() and then call its
> > > methods.

> > > This all works fine, but the OCX generates an event
> > > when it's done doing its work, and I need to have
> > > my program handle the event or all is lost.  I tried
> > > using the "Implements" statement in the declarations
> > > area of my main module, but I get an error from the
> > > IDE.  Can one of you VB experts give me a quick
> > > rundown as to how I can make this EXE handle the
> > > events generated by this OCX?

> > > I have a hunch that this will involve creating
> > > a class module, using Implements in the class, and
> > > instantiating the OCX in the Class_Initialize event
> > > of the class.  Am I right?

> > > PLEASE respond via e-mail, also. Thanks in advance
> > > for the pointers.

> > > --
> > > Morgan Leppink, EquiSoft

> > > MCSE, MCP+I

> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.

> --
> Morgan Leppink, EquiSoft
> MCSE, MCP+I

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. -~=###--WHAT IS THE DIFFERENCE BETWEEN HANDLED EVENTS AND UN-HANDLED EVENTS?---#=~-

2. Handling Project events from COM add-in

3. Handle a vbscript event inside a COM object

4. Handling events fired from an ATL COM object in VBScript

5. handling COM events in VB

6. Handling events from a visual basic COM server in C++

7. Handling COM generated events in eVB...

8. ActiveX control to handle mouseover event handling?

9. A single event handling multiple events

10. handling multiple events with one event handler

11. handling multiple events with a single event handler

12. ATL COM Component firing events into VBScript event sink

 

 
Powered by phpBB® Forum Software