Click here to Skip to main content
12,358,242 members (71,806 online)

C / C++ / MFC

 
AnswerRe: Responding To Asynchronous Functions Pin
TomasRiker217-May-12 8:12
memberTomasRiker217-May-12 8:12 
QuestionHow do I check or change text in a VS2008 menu bar menu item Pin
soaringpilot14-May-12 12:22
membersoaringpilot14-May-12 12:22 
AnswerRe: How do I check or change text in a VS2008 menu bar menu item Pin
«_Superman_»14-May-12 16:32
member«_Superman_»14-May-12 16:32 
GeneralRe: How do I check or change text in a VS2008 menu bar menu item Pin
soaringpilot15-May-12 10:21
membersoaringpilot15-May-12 10:21 
Questionc++ win32, What's the best way to handle large fonts 120 dpi Pin
jkirkerx14-May-12 8:33
memberjkirkerx14-May-12 8:33 
AnswerRe: c++ win32, What's the best way to handle large fonts 120 dpi Pin
enhzflep14-May-12 11:06
memberenhzflep14-May-12 11:06 
GeneralRe: c++ win32, What's the best way to handle large fonts 120 dpi Pin
jkirkerx14-May-12 11:38
memberjkirkerx14-May-12 11:38 
QuestionVfw decompression - real sample code wanted Pin
Vaclav_Sal14-May-12 8:24
memberVaclav_Sal14-May-12 8:24 
QuestionDrawImage from 2 image buffer Pin
john563213-May-12 23:34
memberjohn563213-May-12 23:34 
AnswerRe: DrawImage from 2 image buffer Pin
Richard MacCutchan14-May-12 0:17
mvpRichard MacCutchan14-May-12 0:17 
QuestionIPC using named pipes Pin
ForNow13-May-12 9:27
memberForNow13-May-12 9:27 
GeneralRe: IPC using named pipes Pin
«_Superman_»13-May-12 16:15
member«_Superman_»13-May-12 16:15 
AnswerRe: IPC using named pipes Pin
ThatsAlok13-May-12 20:06
memberThatsAlok13-May-12 20:06 
AnswerRe: IPC using named pipes Pin
TopCoder2314-May-12 0:02
memberTopCoder2314-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:

#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:

#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
memberjkirkerx13-May-12 8:49 
Answer[SOLVED] Re: c++, CryptGetHashParam works in XP, Vista, but not Windows 7 Pin
jkirkerx13-May-12 10:13
memberjkirkerx13-May-12 10:13 
Questionwhere should add the try-catch? Pin
yu-jian13-May-12 5:55
groupyu-jian13-May-12 5:55 
AnswerRe: where should add the try-catch? Pin
Richard MacCutchan13-May-12 6:45
mvpRichard MacCutchan13-May-12 6:45 
GeneralRe: where should add the try-catch? Pin
yu-jian13-May-12 18:39
groupyu-jian13-May-12 18:39 
AnswerRe: where should add the try-catch? Pin
ThatsAlok13-May-12 20:08
memberThatsAlok13-May-12 20:08 
GeneralRe: where should add the try-catch? Pin
Richard MacCutchan13-May-12 21:41
mvpRichard MacCutchan13-May-12 21:41 
AnswerRe: where should add the try-catch? Pin
Vivekuniq13-May-12 20:59
memberVivekuniq13-May-12 20:59 
GeneralRe: where should add the try-catch? Pin
yu-jian13-May-12 22:24
groupyu-jian13-May-12 22:24 
AnswerRe: where should add the try-catch? Pin
Aescleal14-May-12 3:15
memberAescleal14-May-12 3:15 
QuestionNeed Help with Audio Output in C/C++ Pin
Veeshal Beotra13-May-12 4:12
memberVeeshal Beotra13-May-12 4:12 
AnswerRe: Need Help with Audio Output in C/C++ Pin
Vaclav_Sal14-May-12 8:35
memberVaclav_Sal14-May-12 8:35 
QuestionChanging the background color of Text control or combo box when text got changed Pin
ash mishra13-May-12 4:01
memberash 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
member«_Superman_»13-May-12 4:12 
Question'Forward Class Declaration' Not Working Pin
Overloaded_Name12-May-12 20:44
memberOverloaded_Name12-May-12 20:44 
QuestionRe: 'Forward Class Declaration' Not Working Pin
«_Superman_»12-May-12 20:53
member«_Superman_»12-May-12 20:53 
AnswerRe: 'Forward Class Declaration' Not Working Pin
Overloaded_Name12-May-12 22:23
memberOverloaded_Name12-May-12 22:23 
AnswerRe: 'Forward Class Declaration' Not Working Pin
Richard MacCutchan12-May-12 21:30
mvpRichard MacCutchan12-May-12 21:30 
GeneralRe: 'Forward Class Declaration' Not Working Pin
Overloaded_Name12-May-12 22:29
memberOverloaded_Name12-May-12 22:29 
GeneralRe: 'Forward Class Declaration' Not Working Pin
Richard MacCutchan12-May-12 22:34
mvpRichard MacCutchan12-May-12 22:34 
AnswerRe: 'Forward Class Declaration' Not Working Pin
Overloaded_Name12-May-12 22:56
memberOverloaded_Name12-May-12 22:56 
GeneralRe: 'Forward Class Declaration' Not Working Pin
Richard MacCutchan13-May-12 1:18
mvpRichard MacCutchan13-May-12 1:18 
AnswerRe: 'Forward Class Declaration' Not Working Pin
krmed13-May-12 3:34
memberkrmed13-May-12 3:34 
GeneralRe: 'Forward Class Declaration' Not Working Pin
Richard MacCutchan13-May-12 5:04
mvpRichard MacCutchan13-May-12 5:04 
GeneralRe: 'Forward Class Declaration' Not Working Pin
Overloaded_Name13-May-12 6:59
memberOverloaded_Name13-May-12 6:59 
QuestionSubclass Procedure failed for edit control Pin
vishalgpt12-May-12 3:09
membervishalgpt12-May-12 3:09 
AnswerRe: Subclass Procedure failed for edit control Pin
«_Superman_»12-May-12 4:25
member«_Superman_»12-May-12 4:25 
GeneralRe: Subclass Procedure failed for edit control Pin
vishalgpt12-May-12 4:40
membervishalgpt12-May-12 4:40 
GeneralRe: Subclass Procedure failed for edit control Pin
«_Superman_»12-May-12 4:47
member«_Superman_»12-May-12 4:47 
GeneralRe: Subclass Procedure failed for edit control Pin
vishalgpt12-May-12 5:36
membervishalgpt12-May-12 5:36 
QuestionOpening files in c++ Pin
Jirik60727713612-May-12 2:38
memberJirik60727713612-May-12 2:38 
AnswerRe: Opening files in c++ Pin
Richard MacCutchan12-May-12 2:51
mvpRichard MacCutchan12-May-12 2:51 
GeneralRe: Opening files in c++ Pin
Jirik60727713612-May-12 2:56
memberJirik60727713612-May-12 2:56 
AnswerRe: Opening files in c++ Pin
«_Superman_»12-May-12 4:29
member«_Superman_»12-May-12 4:29 
Question64 bit option not coming Pin
sujandasmahapatra11-May-12 7:28
membersujandasmahapatra11-May-12 7:28 
AnswerRe: 64 bit option not coming Pin
Albert Holguin11-May-12 8:08
memberAlbert Holguin11-May-12 8:08 

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.


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 30 Jun 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid