Link to home
Start Free TrialLog in
Avatar of ggilman
ggilman

asked on

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.
Avatar of ggilman
ggilman

ASKER

Edited text of question
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

Avatar of ggilman

ASKER

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

C and VB interperate data in different ways, how is the data defined in your C program and in your VB program?
Avatar of ggilman

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of parkerea
parkerea
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial