VB6 Shared Memory

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.

Who is Participating?
Éric MoreauSenior .Net ConsultantCommented:
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

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
carloslimajrAuthor Commented:
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.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Éric MoreauSenior .Net ConsultantCommented:
>>The data must be exchanged through process in memory.

You have to go the ActiveX EXE way as I pointed too.
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.
carloslimajrAuthor Commented:
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 ?
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:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.