• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Sharing memory between applications

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
ggilman
Asked:
ggilman
1 Solution
 
ggilmanAuthor Commented:
Edited text of question
0
 
mark2150Commented:
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
 
ggilmanAuthor Commented:
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
Industry Leaders: 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!

 
mark2150Commented:
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
 
deightonCommented:
C and VB interperate data in different ways, how is the data defined in your C program and in your VB program?
0
 
ggilmanAuthor Commented:
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
 
parkereaCommented:
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

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now