|
#include <Windows.h>
#include <tchar.h>
#define BUF_SIZE 256 * sizeof (TCHAR)
TCHAR MyEvent[] = _T("Global\\SharedMemoryEvent");
TCHAR szName[]= _T("Global\\MyFileMappingObject");
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
//
// Create the event to communicate between server and client
//
HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, MyEvent);
//
// Start server process
//
PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { 0 };
if (!CreateProcess(_T("Server.exe"), NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
return 1;
//
// Wait for the server to complete the job
//
WaitForSingleObject(hEvent, INFINITE);
//
// Access shared memory object
//
HANDLE hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
szName); // name of mapping object
if (hMapFile == NULL) return 1;
LPCTSTR pBuf = (LPTSTR) MapViewOfFile(
hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
if (pBuf == NULL) return 1;
//
// Shows Server Output
//
MessageBox(NULL, pBuf, _T("Server Output"), MB_OK);
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
//
// Tell the server that the object isn't used any longer
//
SetEvent(hEvent);
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
The languages I know best are: C, C++, C#, Assembly (x86, x64, ARM), MSIL, Python, Lua. The environments I frequently use are: Qt, Win32, MFC, .NET, WDK. I'm a developer and a reverse engineer and I like playing around with internals.
You can find most of my work at
http://ntcore.com.