<code>
HANDLE hFile; // variables are listed at the begining
// there is NO declaration like "var"
HANDLE hTempFile;
DWORD dwBytesRead, dwBytesWritten;
char szTempName[MAX_PATH];
// szTempName would be an Array[0..MAX_PATH] of Char
char buffer[4096];
// Open the file.
hFile = CreateFile("ORIGINAL.TXT", // filename
// double quotes are use like single quote for Text
GENERIC_READ, // open for reading
0, // do not share
NULL, // no security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE) {
ErrorHandler("Could not open file."); // process error
}
// Create a temporary file.
GetTempFileName("\\TEMP", // dir. for temp. files
"NEW", // temp. filename prefix
0, // create unique name
szTempName); // buffer for name
hTempFile = CreateFile((LPTSTR) szTempName, // filename
// the (LPTSTR) szTempName is roughly like Typecasting in Pascal
// PChar(szTempName);
GENERIC_READ | GENERIC_WRITE, // open for read-write
0, // do not share
NULL, // no security
CREATE_ALWAYS, // overwrite existing file
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hTempFile == INVALID_HANDLE_VALUE) {
ErrorHandler("Could not create temporary file.");
}
do
{
if (ReadFile(hFile, buffer, 4096,
&dwBytesRead, NULL)) {
// the & above is roughly like the @ in Pascal
CharUpperBuff(buffer, dwBytesRead);
WriteFile(hTempFile, buffer, dwBytesRead,
&dwBytesWritten, NULL);
}
} while (dwBytesRead == 4096);
CloseHandle(hFile);
CloseHandle(hTempFile);
// Move the temporary file to the new text file.
if (!MoveFile(szTempName, "ALLCAPS.TXT")) {
ErrorHandler("Could not move temp. file.");
}
</code>
why doesnt this work?