473,503 Members | 1,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A Memory Map Code Bit

5 New Member
The following bit of code is only the memory mapping part, but I am unsure about the output area of the code. I know how to bring in an input file, but I am unsure if this code sends out an output file. Also, is there a reference site that I can be pointed to about how to write to the output file. I am stuck on trying to figure out how to get the information from the first file (the input) to the second file (the output). I am pretty sure the code below is incomplete, only on the reason of I don't know how to connect it, and I can't find the correct reading sources to help me out. Thank you in advance.

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. HANDLE OutFile;
  8. HANDLE InFile;
  9. HANDLE InFileMap;
  10. HANDLE OutFileMap;
  11. PVOID InPVFile;
  12. PVOID OutPVFile;
  13. DWORD InDWFileSize;
  14. DWORD OutDWFileSize;
  15. int i;
  16.  
  17. //Opening an input file.
  18.  
  19. char OutFilename[] = “c:\\exe1\\testin.dat”;
  20.  
  21. OutFile = CreateFile(InFilename, 
  22. GENERIC_READ,
  23. 0,
  24. NULL,
  25. OPEN_EXISTING,
  26. FILE_ATTRIBUTE_NORMAL, 
  27. NULL);
  28. if (InFile == INVALID_HANDLE_VALUE)
  29. {
  30.     cout << “File could not be opened.”;
  31.     return(FALSE);
  32. }
  33.  
  34. //Creating a file-mapping kernel object for input.
  35.  
  36. InFileMap = CreatFileMapping(InFile,
  37.     NULL,
  38.     PAGE_READONLY,
  39.     0,
  40.     0,
  41.     NULL);
  42. if (InFileMap == NULL)
  43. {
  44.     cout << “File map could not be opened.”;
  45.     ClosrHandle(InFile);
  46.     return(FALSE);
  47. }
  48.  
  49. //Mapping a view of the input file.
  50.  
  51. InPVFile = MapViewOfFile(InFileMap,
  52.     FILE_MAP_READ,
  53.     0,
  54.     0,
  55.     0);
  56. if (InPVFile == NULL)
  57. {
  58.     cout << “Could not map view of file.”;
  59.     CloseHandle(InFileMap);
  60.     CloseHandle(InFile);
  61.     return(FALSE);
  62. }
  63.  
  64. //Gathering the size of the input file.
  65.  
  66. InDWFileSize = GetFileSize(InFile, NULL);
  67.  
  68. //Creating an output file.
  69.  
  70. char OutFilename[] = “c:\\exe1\\testout.dat”;
  71.  
  72. OutFile = CreateFile(OutFilename, 
  73. GENERIC_READ | GENERIC_WRITE,
  74. 0,
  75.  NULL,
  76.  CREATE_NEW, 
  77. FILE_ATTRIBUTE_NORMAL, 
  78. NULL);
  79. if (OutFile == INVALID_HANDLE_VALUE)
  80. {
  81.     cout << “File could not be created.”;
  82.     return(FALSE);
  83. }
  84.  
  85. //Creating a file-mapping kernel object for output.
  86.  
  87. OutFileMap = CreatFileMapping(OutFile,
  88.     NULL,
  89.     PAGE_WRITECOPY,
  90.     0,
  91.     0,
  92.     NULL);
  93. if (OutFileMap == NULL)
  94. {
  95.     cout << “File map could not be created.”;
  96.     ClosrHandle(OutFile);
  97.     return(FALSE);
  98. }
  99.  
  100. //Mapping a view of the output file.
  101.  
  102. OutPVFile = MapViewOfFile(OutFileMap,
  103.     FILE_MAP_COPY,
  104.     0,
  105.     0,
  106.     0);
  107. if (OutPVFile == NULL)
  108. {
  109.     cout << “Could not map view of file.”;
  110.     CloseHandle(OutFileMap);
  111.     CloseHandle(OutFile);
  112.     return(FALSE);
  113. }
  114.  
  115. //Switching the ASCII characters.
  116.  
  117. //???
  118.  
  119. //Housekeeping
  120.  
  121. UnmapViewOfFile(InPVFile);
  122. UnmapViewOfFile(OutPVFile);
  123. CloseHandle(InFileMap);
  124. CloseHandle(OutFileMap);
  125. CloseHandle(InFile);
  126. CloseHandle(OutFile);
  127. }
  128.  
Oct 14 '07 #1
1 2287
Banfa
9,065 Recognized Expert Moderator Expert
This looks like a rather complex way to copy a file when you could just call CopyFileEx
Nov 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2220
by: Jason Callas | last post by:
I was doing starting some experimenting with the GC and ran into the following odd result. I created an object and my used memory went up by almost 11k but when I cleared it and forced a collection...
18
6654
by: Tron Thomas | last post by:
Given the following information about memory management in C++: ----- The c-runtime dynamic memory manager (and most other commercial memory managers) has issues with fragmentation similar to a...
32
3790
by: John | last post by:
Hi all: When I run my code, I find that the memory that the code uses keeps increasing. I have a PC with 2G RAM running Debian linux. The code consumes 1.5G memory by the time it finishes...
9
2327
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
25
2346
by: Zeng | last post by:
I finally narrowed down my code to this situation, quite a few (not all) of my CMyClass objects got hold up after each run of this function via the simple webpage that shows NumberEd editbox. My...
8
8521
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
62
17619
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
81
4478
by: Peter Olcott | last post by:
It looks like System::Collections::Generic.List throws and OUT_OF_MEMORY exception whenever memory allocated exceeds 256 MB. I have 1024 MB on my system so I am not even out of physical RAM, much...
5
24598
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
5
505
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.