Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <iostream>
  6. #include <tchar.h>
  7. #include <string.h>
  8.  
  9. using namespace std;
  10.  
  11. #define BUF_SIZE 256
  12. TCHAR szName[] = TEXT("Global\\MyFileMappingObject");
  13.  
  14. int _tmain()
  15. {
  16. HANDLE hMapFile;
  17. LPCTSTR pBuf;
  18.  
  19. hMapFile = CreateFileMapping(
  20. INVALID_HANDLE_VALUE, // use paging file
  21. NULL, // default security
  22. PAGE_READWRITE, // read/write access
  23. 0, // maximum object size (high-order DWORD)
  24. BUF_SIZE, // maximum object size (low-order DWORD)
  25. szName); // name of mapping object
  26.  
  27. if (hMapFile == NULL)
  28. {
  29. _tprintf(TEXT("Could not create file mapping object (%d).\n"),
  30. GetLastError());
  31. return 1;
  32. }
  33. pBuf = (LPTSTR)MapViewOfFile(hMapFile, // chwytak do obiektu
  34. FILE_MAP_ALL_ACCESS, // read/write pozwolenie
  35. 0, //gorny rozmar
  36. 0, //dolny rozmoar
  37. BUF_SIZE); // max ilsoc
  38.  
  39. if (pBuf == NULL)
  40. {
  41. _tprintf(TEXT("Could not map view of file (%d).\n"),
  42. GetLastError());
  43.  
  44. CloseHandle(hMapFile);
  45.  
  46. return 1;
  47. }
  48.  
  49.  
  50. //_getch();
  51.  
  52. while (1)
  53. {
  54. char arr[5] = { 'a', 'b', 'c', 'd', 'e' };
  55. char *ptr = arr;
  56. TCHAR szMsg[] = TEXT(&ptr);
  57. CopyMemory((PVOID)pBuf, szMsg, (_tcslen(szMsg) * sizeof(TCHAR))); // gdzie , skąd , ile
  58.  
  59. }
  60.  
  61. UnmapViewOfFile(pBuf);
  62.  
  63. CloseHandle(hMapFile);
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement