I am finishing up a program and have a few issues. I get the following error twice in the program...
error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Can someone please show and explain to me how to set up a cast for this program....
#include <windows.h>
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
//START THE MAIN FUNCTION
int main(int argc, char *argv[])
{
//BEGIN THE INPUT FILE MAPPING
HANDLE hFile;
HANDLE hFileMap;
PVOID pvFile;
DWORD dwFileSize;
int i = 0;
//HAVE USER ENTER THE PATH FOLLOWED BY THE FILE NAME
cout<<"Please enter the path and filename: ";
cout << endl;
//Test for validity
char hFilename[] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Input.txt";
argv[1] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Input.txt";
//ALLOW THE HFILE TO RETURN A HANDLE TO THE OPEN FILE
hFile = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO CHECK IF FILE CAN BE OPENED
if (hFile == INVALID_HANDLE_VALUE)
{
//DISPLAY MESSAGE THAT FILE CANNOT BE OPEN
cout << "File could not be opened.";
return(FALSE);
}
//OPENS A FILE MAPPED OBJECT
hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
//IF STATEMENT TO SEE IF HFILEMAP CAN BE OPENED
if (hFileMap == NULL)
{
//DISPLAY MESSAGE THAT THIS FILE CANNOT BE OPENED
cout << "File map could not be opened";
CloseHandle(hFile);
return(FALSE);
}
//GIVES ADDRESS FOR DATA FILE
pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
//IF STATEMENT TO SEE IF PV FILE CAN BE OPENED
if (pvFile == NULL)
{
//DISPLAY MESSAGE THAT THIS FILE CANNOT BE OPENED
cout << "Could not map view of File";
CloseHandle(hFileMap);
CloseHandle(hFile);
return(FALSE);
}
//GIVES THTE SIZE OF THE FILE
dwFileSize = GetFileSize(hFile, NULL);
//BEGIN OUTPUT FILE MAPPING
HANDLE oFile;
HANDLE oFileMap;
PVOID pvOFile;
DWORD dwOFileSize;
//TEST FOR VALIDITY
char oFilename[] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Output.txt";
argv[2] = "C:\\Users\Bryan\Documents\CSI 345\Palindrome\Output.txt";
//HAVE USER ENTER THE PATH FOLLOWED BY THE FILE NAME
cout << "Please enter path and filename: ";
cout << endl;
//ALLOW THE oFILE TO RETURN A HANDLE TO THE OPEN FILE
oFile = CreateFile(oFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
//IF STATEMENT TO CHECK IF FILE CAN BE OPENED
if (oFile == INVALID_HANDLE_VALUE)
{
//DISPLAY A MESSAGE FILE CANNOT BE OPENED
cout << "outFile could not be opened.";
return(FALSE);
}
//OPENS A FILE MAPPED OBJECT
oFileMap = CreateFileMapping(oFile, NULL, PAGE_READWRITE, 0, dwFileSize, NULL);
//OPENS A FILE MAPPED OBJECT
if (oFileMap == NULL)
{
//DISPLAY A MESSAGE FILE CANNOT BE OPENED
cout << "File map could not be opened";
CloseHandle(oFile);
return(FALSE);
}
//GIVES ADDRESS FOR DATA FILE
pvOFile = MapViewOfFile(oFileMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
//IF STATEMENT TO SEE IF PV FILE CAN BE OPENED
if (pvOFile == NULL)
{
//DISPLAY A MESSAGE FILE CANNOT BE OPENED
cout << "Could not map view of File";
CloseHandle(hFileMap);
CloseHandle(hFile);
return(FALSE);
}
//INPUT FILE SIZE AND OUTPUT FILE SIZE MUST MATCH UP
dwOFileSize = dwFileSize;
//TEST THE SIZE OF THE FILE
cout << "The file size is: " << dwOFileSize << endl;
// pointer to the beginning address
PSTR hptr = (PSTR) pvFile;
PSTR optr = (PSTR) pvOFile;
// CHECK FOR PALINDROMES
char check;
bool palindrome = false;
char testArray [600];
char testOutArray [600];
int icount = 0;
int ocount = dwOFileSize;
int g = 0;
stack<char> stack;
queue<char> queue;
//Begin for statement
for (i = 0; i < dwFileSize; i++)
{
hptr[i];
}
for (i = 0; i < dwFileSize; i++)
{
stack.push(testArray[i]);
}
//CHECKS TO MAKE SURE A SPACE IS NOT FOUND
//IF SPACE IS NOT FOUND BEGIN TO PUSH ALL CHARACTERS TO ARRAYS
if (hptr[i] != ' ')
{
stack.push(testArray[i]);
queue.push(testOutArray[i]);
//TEST OUTPUT
icount++;
}
//IF THERE IS A SPACE COMPARE THE CHARACTERS IN REVERSE ORDER
if (hptr[i] == ' ')
{
//PERFORM WHILE STATEMENT FOR WHEN THTE STACK IS NOT EMPTY
while (!stack.empty())
{
stack.top() = testArray[g];
g ++;
stack.pop() ;
cout << "The top is:" << stack.top() << endl;
ocount --;
int i = 0;
}
}
}