Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: out of process object


Message #1 by "Fredrick J. Krantz" <krunch97@m...> on Wed, 6 Dec 2000 14:45:50 -0000
To create the out of process ActiveX exe and actually use it.  I usually
follow this method:  (I'll explain why at the end)

Create an ActiveX exe project (Select it from the list of project types you
can create).
- Add a single class module called clsConnection.
- Add a reference to a timer dll (whatever you prefer, I use: SSubTmr6 from
vbAccelarator)
- Create your entry sub inside clsConnection
- Create a public Event to return results to your client exe.  (The other
project)
- create a member variable withevents of the timer class.

------------- Example code: --------------------------
' Timer
Private WithEvents mtmrTimer as SSubTmr6.CTimer

' Result exit point
Public Event Result(pstrResult as String)

' Public Entry point
Public Sub Calculate()

' Make sure that the timer is there
if not mtmrTimer is nothing then
Set mtmrTimer = new SSubTmr6.CTimer
end if

' Tell the timer to fire
mtmrTimer.Interval = 1 ' fire immediately

End Sub

' Timer Event
Private Sub mtmrTimer_ThatTime()
Dim lstrResult as String

' stop the timer
mtmrTimer.Interval = 0

' actually do the calculation
' get the result from the port (wherever)
lstrResult = "I have found something"

' tell the client
RaiseEvent Result(lstrResult)

' check if the timer needs to start again??
End Sub
------------- Example code Ends --------------------------


Next create an exe project (Select it from the list of project types you can
create).
- Add a reference to your ActiveX exe
- Add a member variable withevents of the type of class you created.
- Add a command button and a text box onto your form.
- Call it and deal with the response

------------- Example code: --------------------------
' Pointer to ActiveX exe
Private WithEvents mobjServer as Server.clsConnection

' initilization
Private Sub Form_Load()
' Initialize the Server
Set mobjServer = new Server.clsConnection
End Sub

' the user has pressed the calculate button
Private Sub Command1_Click()

' Call the Server calculate function
mobjServer.Calculate

' do some other stuff (we are now running two processes, the remainder of
this function and the Server process)

End Sub

' The Server has responded
Private Sub mobjServer_Result(pstrResult as string)
' display the result to the User
text1.text = pstrResult
End Sub

------------- Example code Ends --------------------------

There ya go you have just create an out of process Server (overkill for the
example I know), the reason I use a timer is to break the thread, as if I
don't return control to the client exe there is no point in creating an out
of process ActiveX exe because the client will just sit there waiting and
unable to process anything until control is returned.

There are some issues you will have to deal with when programming this way
though.  How will you deal with multiple calls to the ActiveX exe before it
has responded to the first call??  (I usually keep a collection of things to
be dealt with, hence the ' check if the timer needs to start again??)

Good luck and I hope that helps
Syphtor



------Original Message------
From: "Fredrick J. Krantz" <krunch97@m...>
To: professional vb <pro_vb@p...>
Sent: December 6, 2000 8:41:08 PM GMT
Subject: [pro_vb] RE: out of process object


How do you do it?

Please give me some steps to follow.

cordially,

Fredrick J. Krantz


----- Original Message -----
From: Liju Thomas <LThomas@e...>
To: professional vb <pro_vb@p...>
Sent: Wednesday, December 06, 2000 9:48 AM
Subject: [pro_vb] RE: out of process object


> Creating an ActiveX Exe Project will help you to create an COM object
> which runs out of process. Once you create this project, there is no
> difference
> in coding style between an  in process and out of process.
>
> Liju
>
> > -----Original Message-----
> > From: Fredrick J. Krantz [SMTP:krunch97@m...]
> > Sent: Wednesday, December 06, 2000 8:46 AM
> > To: professional vb
> > Subject: [pro_vb] out of process object
> >
> > How do I begin a out of process project that I need to be isolated from
> > the original project to return a string value 5 characters long.  What
do
> > I do to create one.  Basically, I need to read a device using a com port
> > and return the value(device is a reader, either bar code or rf or
presence
> > detector).  I do not know where to start.
> >
> > Help, with some steps with instructions.  I have the necessary details
> > such as port configurations and process control.  Just need an eperts
> > assistance.
> >
> > cordially,
> >
> > krunch97
> >




  Return to Index