Solved

::shm_open()

Posted on 2009-05-03
3
981 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 500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

739 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