OpenFileMappingA, sharing data between MQL4 and C++ program

 

Hi, I'm trying to get an MQL4 program to talk to a C++ program via memory space instead of file handling.  I have run the following example successfully:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx

Now i'm trying to port the "second process" to MQL4.

I'm trying to get the EA to Alert the message sent by the first process (C++ program) but running OpenFileMappingA fails.

I have tried the OpenFileMapping and OpenFileMappingA versions, as mql4 prefers ANSI.

 I obviously have the "first process" running in the background and i have this EA running:

#define BUF_SIZE 256
extern string szName = "Global\\MyFileMappingObject";
#import "kernel32.dll"
int OpenFileMappingA(string dwDesiredAccess, bool bInheritHandle, string lpName);
int MapViewOfFile(int hFileMappingObject, string dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, int dwNumberOfBytestoMap);
bool CloseHandle(int handle);
bool UnmapViewOfFile(string lpBaseAddress);
int start()
  {
   int handle = 0;
   string pBuf;
   
   handle = OpenFileMappingA(NULL, TRUE, szName);
   if(handle == 0) Alert("Could not open file mapping object", GetLastError());
   //Alert("next");
   pBuf = MapViewOfFile(handle, NULL, 0, 0, BUF_SIZE);
   /*if(pBuf == 0)
   {
      Alert("Could not map view of file");
      CloseHandle(handle);      
   }*/
   Alert(pBuf);
   UnmapViewOfFile(pBuf);
   CloseHandle(handle);
   
  }

Any ideas ? 


Files:
 
Gabbins:

Hi, I'm trying to get an MQL4 program to talk to a C++ program via memory space instead of file handling.  I have run the following example successfully:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx

Now i'm trying to port the "second process" to MQL4.

I'm trying to get the EA to Alert the message sent by the first process (C++ program) but running OpenFileMappingA fails.

I have tried the OpenFileMapping and OpenFileMappingA versions, as mql4 prefers ANSI.

 I obviously have the "first process" running in the background and i have this EA running:


Any ideas ? 


For the next time would you please use SRC button to post the code.

 

This is how to pass NULL pointer  How to pass a null pointer to a DLL?

I can only find these 2 in mql5 (not mql4) code base, hope that helps : Memory Mapping and File Mapping without DLL

 
phi.nuts:

For the next time would you please use SRC button to post the code.

 

This is how to pass NULL pointer  How to pass a null pointer to a DLL?

I can only find these 2 in mql5 (not mql4) code base, hope that helps : Memory Mapping and File Mapping without DLL



Hi, I have looked at all of those links before.  I have mql4, but looking at the features of MQL5,  I'm gonna look at upgrading my account. By the looks of things mql5 makes external calls alot easier yes ?

Reason: