Solved

Sharing memory between applications

Posted on 1998-12-10
7
271 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now