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. -
#include <windows.h>
-
#include <iostream>
-
using namespace std;
-
int main(int argc, char *argv[])
-
{
-
HANDLE InFile;
-
HANDLE OutFile;
-
HANDLE InFileMap;
-
HANDLE OutFileMap;
-
PVOID InPVFile;
-
PVOID OutPVFile;
-
DWORD InFS;
-
DWORD OutFS;
-
int i;
-
-
if (argv[4] == NULL)
-
{
-
cout << "ERROR:: Not enough parameters." << endl;
-
return (0);
-
}
-
//Opening an input file.
-
InFile = CreateFile(argv[1],
-
GENERIC_READ,
-
0,
-
NULL,
-
OPEN_EXISTING,
-
FILE_ATTRIBUTE_NORMAL,
-
NULL);
-
if (InFile == INVALID_HANDLE_VALUE)
-
{
-
cout << "File could not be opened." << endl;
-
return(false);
-
}
-
//Creating a file-mapping kernel object for input.
-
InFileMap = CreateFileMapping(InFile,
-
NULL,
-
PAGE_READONLY,
-
0,
-
0,
-
NULL);
-
if (InFileMap == NULL)
-
{
-
cout << "File map could not be opened. IN" << endl;
-
CloseHandle(InFile);
-
return(false);
-
}
-
//Mapping a view of the input file.
-
InPVFile = MapViewOfFile(InFileMap,
-
FILE_MAP_READ,
-
0,
-
0,
-
0);
-
if (InPVFile == NULL)
-
{
-
cout << "Could not map view of file." << endl;
-
CloseHandle(InFileMap);
-
CloseHandle(InFile);
-
return(false);
-
}
-
InFS = GetFileSize(InFile, NULL);
-
-
//Create an output file.
-
OutFile = CreateFile(argv[2],
-
GENERIC_READ | GENERIC_WRITE,
-
0,
-
NULL,
-
CREATE_ALWAYS,
-
FILE_ATTRIBUTE_NORMAL,
-
NULL);
-
if (OutFile == INVALID_HANDLE_VALUE)
-
{
-
cout << "Could not create output file." << endl;
-
return(false);
-
}
-
-
-
//Creating a file-mapping kernel object for output.
-
OutFileMap = CreateFileMapping(OutFile,
-
NULL,
-
PAGE_READWRITE,
-
0,
-
0,
-
NULL);
-
if (OutFileMap == NULL)
-
{
-
cout << "File map could not be opened. OUT" << endl << InFS;
-
CloseHandle(OutFile);
-
return(false);
-
}
-
//Mapping a view of the output file.
-
OutPVFile = MapViewOfFile(OutFileMap,
-
FILE_MAP_WRITE,
-
InFS,
-
InFS,
-
0);
-
if (OutPVFile == NULL)
-
{
-
cout << "Could not map view of file." << endl;
-
CloseHandle(OutFileMap);
-
CloseHandle(OutFile);
-
return(false);
-
}
-
//Switching the ASCII characters.
-
-
-
PSTR pchANSI = (PSTR) InPVFile;
-
PSTR pchANSO = (PSTR) OutPVFile;
-
for (i=0; i < InFS; i++)
-
{
-
if (&pchANSI[i] == argv[3])
-
{
-
pchANSO[i] = *argv[4];
-
}
-
else
-
pchANSO[i] = pchANSI[i];
-
}
-
if (i == InFS)
-
{
-
OutPVFile = pchANSO;
-
}
-
//Housekeeping
-
UnmapViewOfFile(InPVFile);
-
UnmapViewOfFile(OutPVFile);
-
CloseHandle(InFileMap);
-
CloseHandle(OutFileMap);
-
CloseHandle(InFile);
-
CloseHandle(OutFile);
-
}
-
1 3256
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:...
|
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...
===============
|
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...
|
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,
|
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)
| |
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...
|
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.....
|
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;
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |