Solved

Sharing memory between applications

Posted on 1998-12-10
7
274 Views
Last Modified: 2012-08-13
I am trying to write two applications that communicate over a shared memory area. One program is in C while the other is in Visual Basic. Can this be done? I'm trying to a pointer from visual basic which I send to the C program when it starts in the shell commmand. The pointer seems to get into the C program correctly but when accessing the pointer, the data at the VB pointer is not the same as what is at the C pointer.
0
Comment
Question by:ggilman
7 Comments
 
LVL 2

Author Comment

by:ggilman
ID: 1449261
Edited text of question
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1449262
Shared memory is tough in implement in your context. This essentially violates the structure of the windows environment. How much data to you need to share? You'ld be better off trying to send messages between the apps instead of using shared memory. There might be a way to do it, but it's going to be real fragile. SHELL starts a completely independent execution thread. Sharing memory is essentially forbidden in this context.

M

0
 
LVL 2

Author Comment

by:ggilman
ID: 1449263
I need to send quite a bit of data. I am currently using a special shared memory board (one that creates a shared memory region accessible to multiple computers) on which my apps work fine but I'm trying to make it such that I don't need the special board when we want to run on just 1 machine. Ideally I would allocate an array in VB and access it from other programs through a pointer to it from the C programs but now the pointers seem to be pointing elsewhere.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 12

Expert Comment

by:mark2150
ID: 1449264
You're going to run afoul of the memory management on advanced CPU's. When your two tasks attempt to hit the shared memory pool at least one (if not both) will be killed for stepping outside it's allocated memory. Your shared memory system will have to provide some sort of OS extension to tell it to share memory.

This thing is going to be GPF city to implement.

M

0
 
LVL 18

Expert Comment

by:deighton
ID: 1449265
C and VB interperate data in different ways, how is the data defined in your C program and in your VB program?
0
 
LVL 2

Author Comment

by:ggilman
ID: 1449266
All data types are 32 bit (longs, floats, etc...). In VB I use arrays of these 32 bit data types in which I use memcpy functions (through DLLs) to store/read the data to/from pre-defined arrays. In C, I use both memcpy as well as using pointers directly to modify/read data. Like I said, it works as is now but I'm trying to elminate the need for a specialized shared memory board. I get the programs to communicate currently by getting the pointer address from routines that come with the specialized shared memory boards. These routines give me the starting address for the shared memory from which I use offsets to access different elements of data.
0
 

Accepted Solution

by:
parkerea earned 100 total points
ID: 1449267
This is really only a partial answer -- more of a pointer to where to look for more info, sinc I have never actually done it myself. Normally sharing memory would be impossible under Win95 or NT because virtual memory gets in the way by remapping addresses -- memory addresses just ain't what they used to be. (On the other hand, such a thing is easy under Win 3.1, which is why one bad app can easily crash the whole environment!)

Win32 apparently provides some API calls for explicitly sharing memory blocks. Dan Appleman wrote an EXCELLENT book "Visual Basic 5.0 Programmer's Guide to the Win32 API" which tackles the ins and outs of using VB to access Windows API calls. Pages 976 through 980 deal with sharing blocks of memory across applications. I expect you would need to use these API calls in both the VB and C apps.

The concept is called "Memory Mapped Files" and uses the following Win32 APIs:
CreateFileMapping, FlushViewOfFile, MapViewOfFile, MapViewOfFileEx, OpenFileMapping, UnmapViewOfFile.

Good luck.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

860 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