Solved

Sharing memory between applications

Posted on 1998-12-10
7
272 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

20 Experts available now in Live!

Get 1:1 Help Now