Click here to Skip to main content
15,889,651 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: c++ win32, What's the best way to handle large fonts 120 dpi Pin
jkirkerx14-May-12 11:38
professionaljkirkerx14-May-12 11:38 
QuestionVfw decompression - real sample code wanted Pin
Vaclav_14-May-12 8:24
Vaclav_14-May-12 8:24 
QuestionDrawImage from 2 image buffer Pin
john563213-May-12 23:34
john563213-May-12 23:34 
AnswerRe: DrawImage from 2 image buffer Pin
Richard MacCutchan14-May-12 0:17
mveRichard MacCutchan14-May-12 0:17 
QuestionIPC using named pipes Pin
ForNow13-May-12 9:27
ForNow13-May-12 9:27 
GeneralRe: IPC using named pipes Pin
«_Superman_»13-May-12 16:15
professional«_Superman_»13-May-12 16:15 
AnswerRe: IPC using named pipes Pin
ThatsAlok13-May-12 20:06
ThatsAlok13-May-12 20:06 
AnswerRe: IPC using named pipes Pin
Software_Developer14-May-12 0:02
Software_Developer14-May-12 0:02 
Try this: Creating Named Shared Memory.

**First Process**

The first process creates the file mapping object by calling the `CreateFileMapping` function with `INVALID_HANDLE_VALUE` and a name for the object. By using the `PAGE_READWRITE` flag, the process has read/write permission to the memory through any file views that are created.
Then the process uses the file mapping object handle that `CreateFileMapping` returns in a call to `MapViewOfFile` to create a view of the file in the process address space. The `MapViewOfFile` function returns a pointer to the file view, `pBuf`. The process then uses the CopyMemory function to write a string to the view that can be accessed by other processes.


Process 1 code:

C#
#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,                       // maximum object size (high-order DWORD)
                 BUF_SIZE,                // maximum object size (low-order DWORD)
                 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;
}


**Second Process**

A second process can access the string written to the shared memory by the first process by calling the `OpenFileMapping` function specifying the same name for the mapping object as the first process. Then it can use the `MapViewOfFile` function to obtain a pointer to the file view, `pBuf`. The process can display this string as it would any other string. In this example, the message box displayed contains the message "Message from first process" that was written by the first process.


Process 2 code:

C#
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#pragma comment(lib, "user32.lib")

#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;
}



Source : [http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx]
Questionc++, CryptGetHashParam works in XP, Vista, but not Windows 7 Pin
jkirkerx13-May-12 8:49
professionaljkirkerx13-May-12 8:49 
Answer[SOLVED] Re: c++, CryptGetHashParam works in XP, Vista, but not Windows 7 Pin
jkirkerx13-May-12 10:13
professionaljkirkerx13-May-12 10:13 
Questionwhere should add the try-catch? Pin
yu-jian13-May-12 5:55
yu-jian13-May-12 5:55 
AnswerRe: where should add the try-catch? Pin
Richard MacCutchan13-May-12 6:45
mveRichard MacCutchan13-May-12 6:45 
GeneralRe: where should add the try-catch? Pin
yu-jian13-May-12 18:39
yu-jian13-May-12 18:39 
AnswerRe: where should add the try-catch? Pin
ThatsAlok13-May-12 20:08
ThatsAlok13-May-12 20:08 
GeneralRe: where should add the try-catch? Pin
Richard MacCutchan13-May-12 21:41
mveRichard MacCutchan13-May-12 21:41 
AnswerRe: where should add the try-catch? Pin
TinyDevices13-May-12 20:59
professionalTinyDevices13-May-12 20:59 
GeneralRe: where should add the try-catch? Pin
yu-jian13-May-12 22:24
yu-jian13-May-12 22:24 
AnswerRe: where should add the try-catch? Pin
Aescleal14-May-12 3:15
Aescleal14-May-12 3:15 
QuestionNeed Help with Audio Output in C/C++ Pin
Veeshal Beotra13-May-12 4:12
Veeshal Beotra13-May-12 4:12 
AnswerRe: Need Help with Audio Output in C/C++ Pin
Vaclav_14-May-12 8:35
Vaclav_14-May-12 8:35 
QuestionChanging the background color of Text control or combo box when text got changed Pin
Ashish Ranjan Mishra13-May-12 4:01
Ashish Ranjan Mishra13-May-12 4:01 
AnswerRe: Changing the background color of Text control or combo box when text got changed Pin
«_Superman_»13-May-12 4:12
professional«_Superman_»13-May-12 4:12 
Question'Forward Class Declaration' Not Working Pin
AmbiguousName12-May-12 20:44
AmbiguousName12-May-12 20:44 
QuestionRe: 'Forward Class Declaration' Not Working Pin
«_Superman_»12-May-12 20:53
professional«_Superman_»12-May-12 20:53 
AnswerRe: 'Forward Class Declaration' Not Working Pin
AmbiguousName12-May-12 22:23
AmbiguousName12-May-12 22:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.