VB6 Shared Memory

Posted on 2006-05-19
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
    LVL 69

    Accepted Solution

    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.


    LVL 17

    Expert Comment

    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

    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.
    LVL 17

    Expert Comment

    LVL 69

    Expert Comment

    by:Éric Moreau
    >>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

    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

    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

    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:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    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…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now