Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


VB6 Shared Memory

Posted on 2006-05-19
Medium Priority
Last Modified: 2013-12-25
I am building an app using vb6. In this app I have an amount of information that needs to be shared between others vb6 app running under the same machine. The data to be shared are some user data type arrays. The app clients must be able to read and write the arrays asynchronously. How is the best way to implement it and get the best performance?

I appreciate any kind of sample code. For example, it could have a main process that hold the data and serve the clients. Client A write a variable in the server process and client B read it.

Question by:carloslimajr
  • 2
  • 2
  • 2
  • +2
LVL 70

Accepted Solution

Éric Moreau earned 1000 total points
ID: 16717961
Hi carloslimajr,

I would consider a database or a file to share data between apps (even on the same PC). If you don't like that, you will need to create a ActiveX EXE with public members in a class having its Instancing property set to MultiUse.

See http://www.vb-helper.com/howto_activex_dll.html

LVL 17

Expert Comment

ID: 16718640
To exchange data beteween applications you can use getsetting and savesetting
Getsetting and savesetting use the registry to store data.

This sample creates the following key in the registry :
HKCU\Software\VB and VBA Program Settings\Project1\Settings

Under "Settings" it creates the additional value
"Hey,I love Microsoft"

Private Sub Form_Load()
zzz = "Hey,I love Microsoft"
'Set some data to registry
SaveSetting App.Title, "Settings", "firmName", zzz '  "App.Title" contains the variable  "Project1"

'read some data from registry
qqq = GetSetting(App.Title, "Settings", "firmName", "sorry, but the registry entry 'firmName' doesn't exist")
MsgBox qqq
' RESULT : a message box pops up with the text - - -> Hey,I love Microsoft
End Sub

'The last parameter of the GetSetting() function allows you to supply a DEFAULT value
'if the requested registry entry is not found...

'Counter = GetSetting(App.Title, "Settings", "Counter", "-1")
'If Counter = "-1" Then        ' no value in registry

Author Comment

ID: 16719370
I wouldn't like to use files or registry to share the data because I think the overhead will be huge. The data must be exchanged through process in memory.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 17

Expert Comment

ID: 16719703
LVL 70

Expert Comment

by:Éric Moreau
ID: 16719848
>>The data must be exchanged through process in memory.

You have to go the ActiveX EXE way as I pointed too.
LVL 18

Expert Comment

ID: 16722699
I agree with emoreau, you should go down the ActiveX Exe. This will enable you to write a 'server' application that other VB apps can get data from.

Author Comment

ID: 16726523
I developed a piece of code using an EXE ActiveX. It worked very fine when I compile the activex with 'Thread pool = 1 thread', but I observed that when I compile the code with 'Thread per Object' or 'Thread pool > 1 thread' set, my public variables are cleaned (they really are reinitialized when a new instance is created). My 'data server process' as we could call him, will be accessed from about 300 another processes per minute on the same machine.

The questions are:

Wouldn't be better compile the EXE ActiveX with Thread per Object or Thread pool > 1 thread option set ?

Using Thread pool = 1 thread, Will these access (read and write) be asyncronous or serialized ?
LVL 19

Assisted Solution

BrianGEFF719 earned 1000 total points
ID: 16727614
I would suggest using pipes. Create a server application that hosts the arrays and use pipes to transfer data back and forth between client applications.

See the following application for example of using named pipes:

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question