Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#8

Re: Strings: von C++ senden - in Delphi empfangen : WIE?

  Alt 8. Sep 2007, 20:06
Delphi-Quellcode:
#include "stdafx.h"
#include <windows.h>
#include <string>
using namespace std;

struct TData {
   char *version;
   int nr;
...
}


int main(int argc, char* argv[])

{
   const char* SHAREDMEMORYSEGMENTID = "CtMySiMcHa";
....
//write
   HANDLE host_handle;
   TData *host_data;
   host_handle =    CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0,sizeof(TData),SHAREDMEMORYSEGMENTID);
   host_data = (TData*)MapViewOfFile(host_handle,FILE_MAP_WRITE,0,0,0);
   host_data->version = "erste";
   host_data->nr = 1;

//read

   HANDLE client_handle;

   TData *client_data;
   client_handle = OpenFileMapping(FILE_MAP_READ,false,SHAREDMEMORYSEGMENTID);
   client_data = (TData*)MapViewOfFile(client_handle,FILE_MAP_READ,0,0,0);

   printf("Inhalt des SM - version: %s\n",client_data->version);
   printf("Inhalt des SM - nr: %i\n",client_data->nr);
...
   UnmapViewOfFile(host_data);
   CloseHandle(host_handle);

   UnmapViewOfFile(client_data);
   CloseHandle(client_handle);

   flushall();
   getchar();   

   return 0;
}
  Mit Zitat antworten Zitat