Solved

::shm_open()

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 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