Solved

Sharing memory between applications

Posted on 1998-12-10
7
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

691 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