473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

get file size problem

I am trying to get the file size of a memory mapped I/O from the input file, and set that size to the output file. Right now the code below is stuck on the kernel mapping for the output. The program is suppose to map an input and an output and transfer all the writing from the input to the output with changes made to a specific ASCII character.

The two problems I'm having trouble understanding are how to get the file size of the input to be the same in the output, and how to actually write data to the output file. If there are any resources out there that I can read up on that would be helpful at least, but msdn is so cryptic that I cannot find what I'm looking for.


Expand|Select|Wrap|Line Numbers
  1. #include <windows.h>
  2. #include <iostream>
  3. using namespace std;
  4. int main(int argc, char *argv[])
  5. {
  6. HANDLE InFile;
  7. HANDLE OutFile;
  8. HANDLE InFileMap;
  9. HANDLE OutFileMap;
  10. PVOID InPVFile;
  11. PVOID OutPVFile;
  12. DWORD InFS;
  13. DWORD OutFS;
  14. int i;
  15.  
  16. if (argv[4] == NULL)
  17. {
  18. cout << "ERROR:: Not enough parameters." << endl;
  19. return (0);
  20. }
  21. //Opening an input file.
  22. InFile = CreateFile(argv[1],
  23. GENERIC_READ,
  24. 0,
  25. NULL,
  26. OPEN_EXISTING,
  27. FILE_ATTRIBUTE_NORMAL,
  28. NULL);
  29. if (InFile == INVALID_HANDLE_VALUE)
  30. {
  31. cout << "File could not be opened." << endl;
  32. return(false);
  33. }
  34. //Creating a file-mapping kernel object for input.
  35. InFileMap = CreateFileMapping(InFile,
  36. NULL,
  37. PAGE_READONLY,
  38. 0,
  39. 0,
  40. NULL);
  41. if (InFileMap == NULL)
  42. {
  43. cout << "File map could not be opened. IN" << endl;
  44. CloseHandle(InFile);
  45. return(false);
  46. }
  47. //Mapping a view of the input file.
  48. InPVFile = MapViewOfFile(InFileMap,
  49. FILE_MAP_READ,
  50. 0,
  51. 0,
  52. 0);
  53. if (InPVFile == NULL)
  54. {
  55. cout << "Could not map view of file." << endl;
  56. CloseHandle(InFileMap);
  57. CloseHandle(InFile);
  58. return(false);
  59. }
  60. InFS = GetFileSize(InFile, NULL);
  61.  
  62. //Create an output file.
  63. OutFile = CreateFile(argv[2],
  64. GENERIC_READ | GENERIC_WRITE,
  65. 0,
  66. NULL,
  67. CREATE_ALWAYS,
  68. FILE_ATTRIBUTE_NORMAL,
  69. NULL);
  70. if (OutFile == INVALID_HANDLE_VALUE)
  71. {
  72. cout << "Could not create output file." << endl;
  73. return(false);
  74. }
  75.  
  76.  
  77. //Creating a file-mapping kernel object for output.
  78. OutFileMap = CreateFileMapping(OutFile,
  79. NULL,
  80. PAGE_READWRITE,
  81. 0,
  82. 0,
  83. NULL);
  84. if (OutFileMap == NULL)
  85. {
  86. cout << "File map could not be opened. OUT" << endl << InFS;
  87. CloseHandle(OutFile);
  88. return(false);
  89. }
  90. //Mapping a view of the output file.
  91. OutPVFile = MapViewOfFile(OutFileMap,
  92. FILE_MAP_WRITE,
  93. InFS,
  94. InFS,
  95. 0);
  96. if (OutPVFile == NULL)
  97. {
  98. cout << "Could not map view of file." << endl;
  99. CloseHandle(OutFileMap);
  100. CloseHandle(OutFile);
  101. return(false);
  102. }
  103. //Switching the ASCII characters.
  104.  
  105.  
  106. PSTR pchANSI = (PSTR) InPVFile;
  107. PSTR pchANSO = (PSTR) OutPVFile;
  108. for (i=0; i < InFS; i++)
  109. {
  110. if (&pchANSI[i] == argv[3])
  111. {
  112. pchANSO[i] = *argv[4];
  113. }
  114. else
  115. pchANSO[i] = pchANSI[i];
  116. }
  117. if (i == InFS)
  118. {
  119. OutPVFile = pchANSO;
  120. }
  121. //Housekeeping
  122. UnmapViewOfFile(InPVFile);
  123. UnmapViewOfFile(OutPVFile);
  124. CloseHandle(InFileMap);
  125. CloseHandle(OutFileMap);
  126. CloseHandle(InFile);
  127. CloseHandle(OutFile);
  128. }
  129.  
Oct 18 '07 #1
1 3235
DumRat
93
There was something to get file size in sys/stat.h. You should try googling for stat() or fstat(). I used one of those two to get file size. I don't remember though.
Oct 18 '07 #2

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

Similar topics

0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
10
by: Brian Henry | last post by:
Hi, I am having a problem with an attachment system I made... it works with files up to ~3MB in size then after that if you try to upload a file it just goes to a "Page can not be displayed" page...
2
by: Buddy Ackerman | last post by:
I'm have Windows 2000 Server and my website allows uploads of files (using <input type="file">) However I have some problems when a user trys to upload a large (>8MB) file. When the user submits...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
9
by: Tristán White | last post by:
Hi I am very new to PHP - actually, this is my second day at it, as I've only recently started a new job last week. We're a charity. I have a "No input file selected" problem. A Google search...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
4
by: pradqdo | last post by:
Hi folks, I have a very strange problem when I try to port my client/server program to cygwin. It is a simple shell program where the server executes client's commands + it can send and receive...
4
by: liberty1 | last post by:
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help. PROBLEM NUMBER 1: Using PHP and MySQL, I am able to upload...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.