Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to pass info between apps 1

Status
Not open for further replies.

RobSchultz

Programmer
Jun 1, 2000
444
US
I have 2 applications running on a single PC that need to pass information (i.e. variables) between themselves (preferrably within memory only). Here are the ideas I have had/tested:

1. Use SendMessage to populate a hidden text box. This seems a bit of a kludge.
2. Use a common dll. This doesn't seem to maintain data between the different applications that reference it. Perhaps there is a technique that will get around this problem.
3. There is also the possibility of using PropertyBag but because of the sensitive nature of the data I don't want to store anything on the hard-drive.
4. Use a common registry/ini/file storage area, but this also uses the hard-drive.
5. A COM client/server: a) i don't know how to do this b)seems a bit more trouble than its worth but, then again, I don't know how to do this [wink]
6. Solution XYZ that I haven't thought of yet that will solve this problem and bring about fulfillment of my karma. [yinyang]

Right now the app is storing the information in a common registry location in a barely encrypted format. I'd like to make the apps a bit more elegant.

TIA, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
There are a variety of solutions. Here are a just a few suggestions:

Use named or anonomous pipes
Use mailslots
Use COM - essentially you need a SingleUse class (which means an ActiveX EXE) to which all your applications can get a reference. It is a lot easier than you might think.
 
strongm,

Thanks for the response:

OK, I tried an ActiveX exe using Single Use (and also tried Persistable and NotPersistable) to no avail. Please take a look at this code:

Code:
'Application.exe
'this is simple executable.  Run 2 instances.  The idea is to be able to type something in the box on one, click send, then click the receive button on the other instance.

Option Explicit
Private oMed As Medium.Class1
  
Private Sub Command1_Click()
  'Exit
  Set oMed = Nothing
  Unload Me
  End
End Sub

Private Sub Command2_Click()
  'Send
  oMed.Value1 = txtVar.Text
End Sub

Private Sub Command3_Click()
  'Receive
  txtVar.Text = oMed.Value1
End Sub

Private Sub Form_Load()
  Set oMed = New Medium.Class1
End Sub

-------------------------------------------------
'medium.exe
'this is simple ActiveX exe. In this example there is one property that I would like to be able to pass between the two open applications.

Option Explicit

Private m_Value1 As String

Public Property Get Value1() As String
  Value1 = m_Value1
  MsgBox "Public Property Get Value1() As String - Returned:" & m_Value1  'test code
End Property

Public Property Let Value1(sNewValue1 As String)
  m_Value1 = sNewValue1
  MsgBox "Public Property Let Value1(sNewValue1 As String) - Set to:" & m_Value1  'test code
End Property

What else do I need to do to get this whole thing to work.

Thanks again, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Basically you need a little bit of glue. The code for the ActiveX needs three parts: a normal module, the message passing class, and a factory class. The factory class is simply used to return a reference to the same message passing class each time you invoke it.

Here's the module code:
[tt]
Option Explicit

Public gSystemVariable As clsSystemGlobal
Public gObjectCount As Long
[/tt]
Here's the factory class (mine happen's to be called GlobalMaker). Make it MultiUse
[tt]
Option Explicit

Public Property Get clsSystemGlobal() As clsSystemGlobal
Set clsSystemGlobal = gSystemVariable
End Property

Private Sub Class_Initialize()
If gSystemVariable Is Nothing Then
Set gSystemVariable = New clsSystemGlobal
End If
gObjectCount = gObjectCount + 1
End Sub

Private Sub Class_Terminate()
gObjectCount = gObjectCount - 1
If gObjectCount = 0 Then
Set gSystemVariable = Nothing
End If
End Sub
[/tt]
And here's the data passing class (in this example I just illustrate a string). Set it to SingleUse (in my example the class is called clsSystemGlobal)
[tt]
Option Explicit

Private mvarVariable As String
Public Property Let Variable(ByVal vData As String)
mvarVariable = vData
End Property

Public Property Get Variable() As String
Variable = mvarVariable
End Property

Ok, now you can use code similar to the following in your applications:
[tt]
Private Sub Command1_Click()
Dim g As GlobalMaker
Dim test As clsSystemGlobal

Set g = New GlobalMaker
Set test = g.clsSystemGlobal

test.Variable = "Hello"

End Sub
 
Thanks!

That worked like a charm (and I actually understand it!).

I appreciate your help,
-Rob Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top