Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

::shm_open()

Posted on 2009-05-03
3
Medium Priority
?
1,021 Views
Last Modified: 2012-05-06
Hi,

I stuck up with 1 problem where i have to convert Unix code to Windows Code
Please help me to get replacement for following api in to Win32(Windows)

::shm_open() - is, POSIX shared memory objects created .


Thanks...
0
Comment
Question by:palhade
[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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 1500 total points
ID: 24292852
You can use the function CreateFileMapping

Check this link
http://msdn.microsoft.com/en-us/library/aa366551(VS.85).aspx
0
 
LVL 86

Expert Comment

by:jkr
ID: 24296632
A little mroe details and sample code (also attached below) here: http://msdn.microsoft.com/en-us/library/aa366551(VS.85).aspx ("Creating Named Shared Memory")

Also take a look at the article at http://www.codeproject.com/KB/threads/sharedmemipc.aspx ("Interprocess Communication using Shared Memory") which cokmes wit hfull source code and explains that issue in detail.
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
 
#define BUF_SIZE 256
TCHAR szName[]=TEXT("Global\\MyFileMappingObject");
TCHAR szMsg[]=TEXT("Message from first process.");
 
int _tmain()
{
   HANDLE hMapFile;
   LPCTSTR pBuf;
 
   hMapFile = CreateFileMapping(
                 INVALID_HANDLE_VALUE,    // use paging file
                 NULL,                    // default security 
                 PAGE_READWRITE,          // read/write access
                 0,                       // max. object size 
                 BUF_SIZE,                // buffer size  
                 szName);                 // name of mapping object
 
   if (hMapFile == NULL) 
   { 
      _tprintf(TEXT("Could not create file mapping object (%d).\n"), 
             GetLastError());
      return 1;
   }
   pBuf = (LPTSTR) MapViewOfFile(hMapFile,   // handle to map object
                        FILE_MAP_ALL_ACCESS, // read/write permission
                        0,                   
                        0,                   
                        BUF_SIZE);           
 
   if (pBuf == NULL) 
   { 
      _tprintf(TEXT("Could not map view of file (%d).\n"), 
             GetLastError()); 
 
	   CloseHandle(hMapFile);
 
      return 1;
   }
 
   
   CopyMemory((PVOID)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR)));
    _getch();
 
   UnmapViewOfFile(pBuf);
 
   CloseHandle(hMapFile);
 
   return 0;
}
 
--------------------------------->8-------------------------------
 
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
 
#define BUF_SIZE 256
TCHAR szName[]=TEXT("Global\\MyFileMappingObject");
 
int _tmain()
{
   HANDLE hMapFile;
   LPCTSTR pBuf;
 
   hMapFile = OpenFileMapping(
                   FILE_MAP_ALL_ACCESS,   // read/write access
                   FALSE,                 // do not inherit the name
                   szName);               // name of mapping object 
 
   if (hMapFile == NULL) 
   { 
      _tprintf(TEXT("Could not open file mapping object (%d).\n"), 
             GetLastError());
      return 1;
   } 
 
   pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object
               FILE_MAP_ALL_ACCESS,  // read/write permission
               0,                    
               0,                    
               BUF_SIZE);                   
 
   if (pBuf == NULL) 
   { 
      _tprintf(TEXT("Could not map view of file (%d).\n"), 
             GetLastError()); 
 
	  CloseHandle(hMapFile);
 
      return 1;
   }
 
   MessageBox(NULL, pBuf, TEXT("Process2"), MB_OK);
 
   UnmapViewOfFile(pBuf);
 
   CloseHandle(hMapFile);
 
   return 0;
}

Open in new window

0
 
LVL 86

Expert Comment

by:jkr
ID: 24316774
???
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

688 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