473,802 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get file size problem

5 New Member
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 3256
DumRat
93 New Member
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
3945
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
10
3090
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 like it tried to do it but errored... I thought changeing the max size for the file input box to about 100mb would fix it but nope here is my page code and my code behind code... ===============
2
1409
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 the form within about 5 seconds an error message is returned (in FireFox it says "the document contains no data" in IE 6 it just redirects to a page that says the "the page cannot be found". When I look in my webserver log it shows a 400 error. Of...
6
4139
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 comes back with all the data intact, except for the upload object. The text box for "MyFile" (my example) is always cleared. Why is that and is there a way to stop that from happening? Thanks,
18
4355
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 get it to upload a file to the FTP server. I just get a "Cannot connect to remote server" error after this TRY: s = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
4
4488
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 one of my webform pages which includes a button that pops up a window where you can upload files, if you upload files in this popup window, it seems to somehow clear out all of the session variables and the users get logged out. However, if...
9
4848
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 has shown me that this is a common problem, but I have tried to follow all the various instructions but none of them make any difference. First of all... Some background on the page it links from.....
9
5214
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 facing problems: Assume that FILE* filePointer; unsigned char lineBuffer;
4
5710
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 files (something like ftp server/client). I implemented all the commands which the server executes from scratch meaning I don't use fork and exec. It was very educational but my problem is that when I try to "get <filename>" from server to the...
4
2960
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 picture successfully unto the server but not so with the file name of the picture even though other parameters in my form got inserted successfuly in the database. I have read several posts on this topic including here on this site but I can't get around...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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 we have to send another system
2
3792
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.