COM object scope -- Help 
Author Message
 COM object scope -- Help

I despirately need to create a com object "Active-x exe or dll" to manage
serial communications for several instances of the client program. I have
only one serial port device and I need this object to do the serial stuff
for all.

I can create the object and it works but I need more instances of my calling
program to use the same copy since I cannot open the serial port but once
and it needs to stay open.

If I can make this object viewable by all instances I can pass the data back
to the appropriate program and all is well.

I have played with all of the Instancing properties and tried looking up
this stuff in MSDN but don't seem to be able to put my finger on the
solution.

All of my code is in a class object in an active-x exe. I also tried putting
it in a dll but had no luck there either.

--

Tommy Martin



Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help
You will need to use an ActiveX exe and use an instancing
property of SingleUse or GlobalSingleUse.



Quote:
> I despirately need to create a com object "Active-x exe or dll" to
manage
> serial communications for several instances of the client program. I
have
> only one serial port device and I need this object to do the serial
stuff
> for all.

> I can create the object and it works but I need more instances of my
calling
> program to use the same copy since I cannot open the serial port but
once
> and it needs to stay open.

> If I can make this object viewable by all instances I can pass the
data back
> to the appropriate program and all is well.

> I have played with all of the Instancing properties and tried looking
up
> this stuff in MSDN but don't seem to be able to put my finger on the
> solution.

> All of my code is in a class object in an active-x exe. I also tried
putting
> it in a dll but had no luck there either.

> --

> Tommy Martin

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


Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help
Wait a sec.  You do need to create an ActiveX exe, but to get a
reference to an existing object you can use GetObject.  Look
it up in the MSDN for more info.


Quote:

> You will need to use an ActiveX exe and use an instancing
> property of SingleUse or GlobalSingleUse.



> > I despirately need to create a com object "Active-x exe or dll" to
> manage
> > serial communications for several instances of the client program. I
> have
> > only one serial port device and I need this object to do the serial
> stuff
> > for all.

> > I can create the object and it works but I need more instances of my
> calling
> > program to use the same copy since I cannot open the serial port but
> once
> > and it needs to stay open.

> > If I can make this object viewable by all instances I can pass the
> data back
> > to the appropriate program and all is well.

> > I have played with all of the Instancing properties and tried
looking
> up
> > this stuff in MSDN but don't seem to be able to put my finger on the
> > solution.

> > All of my code is in a class object in an active-x exe. I also tried
> putting
> > it in a dll but had no luck there either.

> > --

> > Tommy Martin

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

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


Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help
I followed my own advise and looked up GetObject and found this:
"You can't use GetObject to obtain a reference to a class created with
Visual Basic."
Oops.


Quote:

> Wait a sec.  You do need to create an ActiveX exe, but to get a
> reference to an existing object you can use GetObject.  Look
> it up in the MSDN for more info.



> > You will need to use an ActiveX exe and use an instancing
> > property of SingleUse or GlobalSingleUse.



> > > I despirately need to create a com object "Active-x exe or dll" to
> > manage
> > > serial communications for several instances of the client
program. I
> > have
> > > only one serial port device and I need this object to do the
serial
> > stuff
> > > for all.

> > > I can create the object and it works but I need more instances of
my
> > calling
> > > program to use the same copy since I cannot open the serial port
but
> > once
> > > and it needs to stay open.

> > > If I can make this object viewable by all instances I can pass the
> > data back
> > > to the appropriate program and all is well.

> > > I have played with all of the Instancing properties and tried
> looking
> > up
> > > this stuff in MSDN but don't seem to be able to put my finger on
the
> > > solution.

> > > All of my code is in a class object in an active-x exe. I also
tried
> > putting
> > > it in a dll but had no luck there either.

> > > --

> > > Tommy Martin

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

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

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


Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help

Quote:

> I despirately need to create a com object "Active-x exe or dll" to manage
> serial communications for several instances of the client program. I have
> only one serial port device and I need this object to do the serial stuff
> for all.

Create it as an ActiveX Exe. Set instancing to MultiUse. Let all your variables
and data structures in this be globals in a BAS module. Let the class itself
act as an accessor. It has only methods and properties which update or use
the globals. The class itself has no variables or data structures that deal with
the serial port.

This class has to have some mechanism (critica sections etc) for ensuring that
multiple simultaneous client calls don't corrupt the data.

--
MikeC

Please reply to the group.



Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help
Thomas,

Try implementing a 'singleton' design pattern.  See the book 'Design
Patterns in VB' (?) from MS Press; it includes COM gotchas.  The good news
is it *is* doable.

--A



Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help
This is an example of the Singleton design pattern. There is a discussion by
Deborah Kurata at http://www.insteptech.com/ - look for  "Software design"
and "Design Patterns".

Basically the ActiveX EXE is the right approach. The class for the serial
port should be "Public Not Creatable". Clients get a reference to a
SerialPort object by calling a method of factory class (a "multi-use"
class). You also need a code (BAS) module with a global variable that can
hold a reference to the SerialPort object.

When a client asks for a SerialPort object, the factory class first checks
the global var. If it's Nothing then it creates a new SerialPort object,
returns a reference to the client and also stores a reference in the global
var. If the var already contains a reference, it just returns this reference
to the client.

The only problem then is killing the singleton- you will probably need
maintain a reference count in the BAS module, and require clients to call a
"disconnect" method in the factory class. When the count goes to 0 the
factory class can set the global reference var to Nothing.

--
RobSmith



Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help
forgive me if Im way off base, but isnt this a good case for DDE? Dynamic
Data Exchange right?   lets two or more applications share info just like
computers on a network, one app could be the "Serial port messenger", the
other apps could ask the port messenger to send/recieve data for them?

--


Quote:
> I despirately need to create a com object "Active-x exe or dll" to manage
> serial communications for several instances of the client program. I have
> only one serial port device and I need this object to do the serial stuff
> for all.

> I can create the object and it works but I need more instances of my
calling
> program to use the same copy since I cannot open the serial port but once
> and it needs to stay open.

> If I can make this object viewable by all instances I can pass the data
back
> to the appropriate program and all is well.

> I have played with all of the Instancing properties and tried looking up
> this stuff in MSDN but don't seem to be able to put my finger on the
> solution.

> All of my code is in a class object in an active-x exe. I also tried
putting
> it in a dll but had no luck there either.

> --

> Tommy Martin



Wed, 18 Jun 1902 08:00:00 GMT  
 COM object scope -- Help

Quote:



> >forgive me if Im way off base, but isnt this a good case for DDE?
Dynamic
> >Data Exchange right?   lets two or more applications share info just
like
> >computers on a network, one app could be the "Serial port
messenger", the
> >other apps could ask the port messenger to send/recieve data for
them?

> Personally I find ActiveX.Exes far easier to use than DDE, you can get
> the same result, but with much cleaner code.

> I have a strong suspicion that DDE is actually involved in
> communication with ActiveX.Exes. Has anyone any ideas on this?

DDE is not involved in COM any more, OLE2 is glorified subroutine
calls. OLE1 did depend upon DDE. DDE is an asynchronous messaging
mechansm and so it does not produce the same result under all
conditions, especially errors.

The built in VB DDE mechanism results in messy code, but our DDE
controls have a clean class structure. I'm not suggesting that you
should necessarily use DDE instead of OLE in this case, it depends on
the communication characteristics you desire.
--
Roger Abbott, RHA (Minisystems) Ltd - http://www.rhaminisys.com
DDE Client and Server ActiveX controls for Visual Basic
DDE FAQ and DDE utility tools,
Program launcher/setup menu, other freeware and shareware

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



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

 Relevant Pages 

1. COM object scope -- Help

2. COM-Object in ASP with COM-Object as parameter

3. COM-Object in ASP with COM-Object as Parameter

4. Access a COM object of a COM object?

5. Accessing a COM object of a COM object

6. com object will not read registry when com object called from asp (vb works fine)

7. COM Object-Out of stack space on executing/shell exe from com object

8. Call VB DLL or COM object from within VB COM object or EXE

9. COM Component on Application Scope

10. Scope of database and workspace objects?

11. Tabledef object variable lost out of scope

12. Object Scope & Instantiation

 

 
Powered by phpBB® Forum Software