Thread: memory mapping

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    15

    memory mapping

    I keep getting a file a not found when doing memory mapping...

    Can someone take a look and offer any feedback on what is going on...

    Code:
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <list>
    using namespace std;
    
    bool isPalindrome(const std::string& s)
    {
        std::string sReverse = s;
        std::reverse(sReverse.begin(), sReverse.end());
        return s == sReverse;  // return true if the reverse is the same as non-reverse
    }
    
    
    //MAIN FUNCTION
    int main(int argc, char *argv[]){
    
    	HANDLE readFile, writeFile;
    	HANDLE readFileMap, writeFileMap;
    	PVOID pvreadFile, pvwriteFile;
    	DWORD readFileSize;
    	string word = "";
    	list<string> words;
    
    	//Test Files -------------------------------------------------------------
    			 char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
    			 argv[1] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
    	 //--------------------------------------------------------------------------
    
    	//VERIFYING ARGUMENTS
    	LPCTSTR *myStr1 = (LPCTSTR *)argv[1];
    	if(argc>1)
    	{
    		readFile = CreateFile(argv[1], GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		//IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
    		if(readFile == INVALID_HANDLE_VALUE)
    		{
    			//DISPLAY ERROR MESSAGE
    			std::cout << "Read file could not be opened." << std::endl;
    			return(FALSE);
    		}
    
    		readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
    
    		//IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
    		if(readFileMap == NULL)
    		{
    			//DISPLAY ERROR MESSAGE
    			std::cout << "Read file map could not be opened." << std::endl;
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
    
    		//IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
    		if(pvreadFile == NULL)
    		{
    			//DISPLAY ERROR MESSAGE
    			std::cout << "Could not map view of read file." << std::endl;
    			CloseHandle(readFileMap);
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		//DETERMINE SIZE LIMIT OF INPUT FILE
    		readFileSize = GetFileSize(readFile, NULL);
    
    		//writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    		LPCTSTR *myStr2 = (LPCTSTR *)argv[2]; 
    
    		//Test Files -------------------------------------------------------------
    			 char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
    			 argv[2] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
    		//--------------------------------------------------------------------------
    
    
    		writeFile = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		//IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
    		if(writeFile == INVALID_HANDLE_VALUE)
    		{
    			//DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
    			std::cout << "Write file could not be opened." << std::endl;
    			//std::cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << std::endl;
    			UnmapViewOfFile(pvreadFile);
    			CloseHandle(readFileMap);
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
    
    		//IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
    		if(writeFileMap == NULL)
    		{
    			//DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
    			std::cout << "Write File could not be mapped." << std::endl;
    			CloseHandle(writeFile);
    			UnmapViewOfFile(pvreadFile);
    			CloseHandle(readFileMap);
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
    
    		//IF STATEMENT IF THE PVWRITEFILE IS NULL
    		if(pvwriteFile == NULL)
    		{
    			//DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
    			std::cout << "Could not open map view of write file." << std::endl;
    		}
    
    		//POINTERS NEED TO BE CREATED
    		PSTR readptr = (PSTR) pvreadFile;
    		PSTR writeptr = (PSTR) pvwriteFile;
    
    		{
        bool ret = isPalindrome( "eve redivider" );
    }
    
    		//CLEANUP THE FILE
    		UnmapViewOfFile(pvwriteFile);
    		UnmapViewOfFile(pvreadFile);
    		CloseHandle(writeFileMap);
    		CloseHandle(readFileMap);
    		CloseHandle(writeFile);
    		CloseHandle(readFile);
    	}
    	//ELSE STATEMENT IF CANNOT FIND FILE
    	else 
    		//DISPLAY ERROR MESSAGE THAT NO FILE IS GIVEN
    		cout << "No file given" << endl << endl;
    
    	//RETURN A VALUE
    	return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Quote Originally Posted by http://msdn.microsoft.com/en-us/library/aa366537%28v=vs.85%29.aspx
    Return Value

    If the function succeeds, the return value is a handle to the newly created file mapping object.

    If the object exists before the function call, the function returns a handle to the existing object (with its current size, not the specified size), and GetLastError returns ERROR_ALREADY_EXISTS.

    If the function fails, the return value is NULL. To get extended error information, call GetLastError.
    Add some code to ALL your error paths to call GetLastError(), maybe even format it as a nice string.

    When you know more about why it fails (more than "it doesn't work"), you might be able to figure out what your next step is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You'd think someone with SO MANY POSTS on another forum would have figured out that cross-posting is a bad thing by now.
    Well done.

    But wait, there's more

    Seriously, between the gimmetehcodez wannabies, cross-posting twits, scoop-and-poop morons, and other random detritus, it's getting harder and harder to find decent posts from genuine people who might actually be worth the time responding to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    15
    Made a few changes and it goes to read file map cannot be found so it does go down a little bit

    Code:
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <list>
    using namespace std;
    
    bool isPalindrome(const std::string& s)
    {
        return s == string(s.rbegin(),s.rend());
        
    }
    
    
    //MAIN FUNCTION
    int main(int argc, char *argv[]){
    
    	LPCTSTR *myStr1 = (LPCTSTR *)argv[1];
    	HANDLE readFile, writeFile;
    	HANDLE readFileMap, writeFileMap;
    	PVOID pvreadFile, pvwriteFile;
    	DWORD readFileSize;
    	string word = "";
    	list<string> words;
    
    	//Test Files -------------------------------------------------------------
    			 char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
    			 //argv[1] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
    	 //--------------------------------------------------------------------------
    
    	//VERIFYING ARGUMENTS
    	
    	if(argc=2)
    	{
    		readFile = CreateFile(inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		//IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
    		if(readFile == INVALID_HANDLE_VALUE)
    		{
    			//DISPLAY ERROR MESSAGE
    			std::cout << "Read file could not be opened." << std::endl;
    			std::cout << "value of GetLastError() is " <<  GetLastError() << "\n";
    
    			return(FALSE);
    		}
    
    		readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
    
    		//IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
    		if(readFileMap == NULL)
    		{
    			//DISPLAY ERROR MESSAGE
    			std::cout << "Read file map could not be opened." << std::endl;
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
    
    		//IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
    		if(pvreadFile == NULL)
    		{
    			//DISPLAY ERROR MESSAGE
    			std::cout << "Could not map view of read file." << std::endl;
    			CloseHandle(readFileMap);
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		//DETERMINE SIZE LIMIT OF INPUT FILE
    		readFileSize = GetFileSize(readFile, NULL);
    
    		//writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    		//LPCTSTR *myStr2 = (LPCTSTR *)argv[2]; 
    
    		//Test Files -------------------------------------------------------------
    			 char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
    			 //argv[2] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
    		//--------------------------------------------------------------------------
    
    
    		writeFile = CreateFile(outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		//IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
    		if(writeFile == INVALID_HANDLE_VALUE)
    		{
    			//DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
    			std::cout << "Write file could not be opened." << std::endl;
    			//std::cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << std::endl;
    			UnmapViewOfFile(pvreadFile);
    			CloseHandle(readFileMap);
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
    
    		//IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
    		if(writeFileMap == NULL)
    		{
    			//DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
    			std::cout << "Write File could not be mapped." << std::endl;
    			CloseHandle(writeFile);
    			UnmapViewOfFile(pvreadFile);
    			CloseHandle(readFileMap);
    			CloseHandle(readFile);
    			return(FALSE);
    		}
    
    		pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
    
    		//IF STATEMENT IF THE PVWRITEFILE IS NULL
    		if(pvwriteFile == NULL)
    		{
    			//DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
    			std::cout << "Could not open map view of write file." << std::endl;
    		}
    
    		//POINTERS NEED TO BE CREATED
    		PSTR readptr = (PSTR) pvreadFile;
    		PSTR writeptr = (PSTR) pvwriteFile;
    
    		{
        bool ret = isPalindrome( "eve redivider" );
    }
    
    		//CLEANUP THE FILE
    		UnmapViewOfFile(pvwriteFile);
    		UnmapViewOfFile(pvreadFile);
    		CloseHandle(writeFileMap);
    		CloseHandle(readFileMap);
    		CloseHandle(writeFile);
    		CloseHandle(readFile);
    	}
    	//ELSE STATEMENT IF CANNOT FIND FILE
    	else 
    		//DISPLAY ERROR MESSAGE THAT NO FILE IS GIVEN
    		cout << "No file given" << endl << endl;
    
    	//RETURN A VALUE
    	return 0;
    }

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You don't have "read file map cannot be found" in your program anywhere, so you might want to reread your screen. And why did you stop calling GetLastError? Every one of your error checks should call it and display the result.

  6. #6
    Registered User
    Join Date
    May 2011
    Posts
    15
    im sorry I meant...

    "Read file map could not be opened."

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Okay. You still need to call GetLastError.

    Also, you may want to change argc=2 to argc==2, unless you intend to change the value of argc for whatever reason.

  8. #8
    Registered User
    Join Date
    May 2011
    Posts
    15
    I changed some things back and get the message "way too many arguments given"

  9. #9
    Registered User
    Join Date
    May 2011
    Posts
    15
    code might help...

    Code:
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <list>
    using namespace std;
    
    bool isPalindrome(const std::string& s)
    {
        return s == string(s.rbegin(),s.rend());
    }
    
    //MAIN FUNCTION
    int main(int argc, char *argv[]){
    
        HANDLE readFile, writeFile;
        HANDLE readFileMap, writeFileMap;
        PVOID pvreadFile, pvwriteFile;
        DWORD readFileSize;
        string word = "";
        list<string> words;
    
    	//Test file
    	char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
    
        //VERIFYING ARGUMENTS
        if(argc == 2 )
        {
            cout << "opening for read: " << argv[1] << endl;
            readFile = CreateFile(inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
            //IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
            if(readFile == INVALID_HANDLE_VALUE)
            {
                //DISPLAY ERROR MESSAGE
                cout << "Read file could not be opened. Error code: " << GetLastError() << endl;
                return(FALSE);
            }
    
            readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
    
            //IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
            if(readFileMap == NULL)
            {
                //DISPLAY ERROR MESSAGE
                cout << "Read file map could not be opened. Error code: " << GetLastError() << endl;
                CloseHandle(readFile);
                return(FALSE);
            }
    
            pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
    
            //IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
            if(pvreadFile == NULL)
            {
                //DISPLAY ERROR MESSAGE
                cout << "Could not map view of read file. Error code: " << GetLastError() << endl;
                CloseHandle(readFileMap);
                CloseHandle(readFile);
                return(FALSE);
            }
    
            //DETERMINE SIZE LIMIT OF INPUT FILE
            readFileSize = GetFileSize(readFile, NULL);
    
            cout << "Opening for write: " << argv[2] << endl;
            //writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		//test file
    		char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
    
            writeFile = CreateFile(outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
            //IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
            if(writeFile == INVALID_HANDLE_VALUE)
            {
                //DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
                cout << "Write file could not be opened. Error code: " << GetLastError() << endl;
                //cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << endl;
                UnmapViewOfFile(pvreadFile);
                CloseHandle(readFileMap);
                CloseHandle(readFile);
                return(FALSE);
            }
    
            writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
    
            //IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
            if(writeFileMap == NULL)
            {
                //DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
                cout << "Write File could not be mapped. Error code: " << GetLastError() << endl;
                CloseHandle(writeFile);
                UnmapViewOfFile(pvreadFile);
                CloseHandle(readFileMap);
                CloseHandle(readFile);
                return(FALSE);
            }
    
            pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
    
            //IF STATEMENT IF THE PVWRITEFILE IS NULL
            if(pvwriteFile == NULL)
            {
                //DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
                cout << "Could not open map view of write file. Error code: " << GetLastError() << endl;
            }
    
            //CLEANUP THE FILE
            UnmapViewOfFile(pvwriteFile);
            UnmapViewOfFile(pvreadFile);
            CloseHandle(writeFileMap);
            CloseHandle(readFileMap);
            CloseHandle(writeFile);
            CloseHandle(readFile);
    
        }
        //ELSE STATEMENT IF CANNOT FIND FILE
        else
        {
            //DISPLAY ERROR MESSAGE THAT NO FILE IS Given
            switch( argc )
            {
                case 0:
                    cout << "No arguments given" << endl;
                    break;
                case 1:
                    cout << "No read file or write file given" << endl;
                    break;
                case 2:
                    cout << "No write file given" << endl;
                    break;
                default:
                    cout << "Way too many arguments given." << endl;
            }
        }
    
        cout << "Arg 0 = file to read" << endl;
        cout << "Arg 1 = file to write to" << endl;
    
        //RETURN A VALUE
        return 0;
    }

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    How many arguments are you expecting? If argc==2, that corresponds to one argument. If you are expecting two arguments, then argc would equal 3 (one for the program name, and two for the user-supplied arguments).

  11. #11
    Registered User
    Join Date
    May 2011
    Posts
    15
    And tried debugging and message pops up no read file or write file given

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So stop for a minute. How many arguments are you supposed to give the program? Once you know that, then give the program that many arguments. (And make sure the argc check matches that number.)

  13. #13
    Registered User
    Join Date
    May 2011
    Posts
    15
    Ok I think I am making progress on this now. I try to debug and it goes through and tries to open but crashes which I expect as I have set this up for memory mapping but when I open with command prompt I get the message "too many arguments given" Just want to see if I am getting close...

    Code:
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <list>
    using namespace std;
    
    bool isPalindrome(const std::string& s)
    {
        return s == string(s.rbegin(),s.rend());
    }
    
    //MAIN FUNCTION
    int main(int argc, char *argv[]){
    
        HANDLE readFile, writeFile;
        HANDLE readFileMap, writeFileMap;
        PVOID pvreadFile, pvwriteFile;
        DWORD readFileSize;
        string word = "";
        list<string> words;
    
    	//Test file
    	char inFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Input.txt";
    
        //VERIFYING ARGUMENTS
        if(argc == 1 )
        {
            cout << "opening for read: " << argv[1] << endl;
            readFile = CreateFile(inFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
            //IF STATEMENT TO CHECK IF THE READ FILE IS NOT VALID
            if(readFile == INVALID_HANDLE_VALUE)
            {
                //DISPLAY ERROR MESSAGE
                cout << "Read file could not be opened. Error code: " << GetLastError() << endl;
                return(FALSE);
            }
    
            readFileMap = CreateFileMapping(readFile, NULL, PAGE_READONLY, 0, 0, NULL);
    
            //IF STATEMENT TO SEE IF THE READFILEMAP IS NULL
            if(readFileMap == NULL)
            {
                //DISPLAY ERROR MESSAGE
                cout << "Read file map could not be opened. Error code: " << GetLastError() << endl;
                CloseHandle(readFile);
                return(FALSE);
            }
    
            pvreadFile = MapViewOfFile(readFileMap, FILE_MAP_READ, 0, 0, 0);
    
            //IF STATEMENT TO DETERMINE IF PVREADFILE IS NULL
            if(pvreadFile == NULL)
            {
                //DISPLAY ERROR MESSAGE
                cout << "Could not map view of read file. Error code: " << GetLastError() << endl;
                CloseHandle(readFileMap);
                CloseHandle(readFile);
                return(FALSE);
            }
    
            //DETERMINE SIZE LIMIT OF INPUT FILE
            readFileSize = GetFileSize(readFile, NULL);
    
            cout << "Opening for write: " << argv[2] << endl;
            //writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		//test file
    		char outFilename[] = "C:\\Users\\Bryan\\Documents\\CSI 345\\Palindrome\\Palindrome\\Output.txt";
    
            writeFile = CreateFile(outFilename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    
            //IF STATEMENT TO DETERMINE IF WRITE FILE IS VALID OR NOT
            if(writeFile == INVALID_HANDLE_VALUE)
            {
                //DISPLAY ERROR MESSSAGE IF FILE CAN'T BE OPENED
                cout << "Write file could not be opened. Error code: " << GetLastError() << endl;
                //cout << "argv[1] = " << argv[1] << " argv[2] = " << argv[2] << endl;
                UnmapViewOfFile(pvreadFile);
                CloseHandle(readFileMap);
                CloseHandle(readFile);
                return(FALSE);
            }
    
            writeFileMap = CreateFileMapping(writeFile, NULL, PAGE_READWRITE, 0, readFileSize, NULL);
    
            //IF STATEMENT TO DETERMINE IF WRITE FILE MAP IS NULL
            if(writeFileMap == NULL)
            {
                //DISPLAY ERROR MESSAGE THAT THE WRITE FILE CANNOT BE MAPPED
                cout << "Write File could not be mapped. Error code: " << GetLastError() << endl;
                CloseHandle(writeFile);
                UnmapViewOfFile(pvreadFile);
                CloseHandle(readFileMap);
                CloseHandle(readFile);
                return(FALSE);
            }
    
            pvwriteFile = MapViewOfFile(writeFileMap, FILE_MAP_WRITE, 0,0,0);
    
            //IF STATEMENT IF THE PVWRITEFILE IS NULL
            if(pvwriteFile == NULL)
            {
                //DISPLAY ERROR MESSAGE THAT I COULD NOT OPEN MAP VIEW OF WRITE FILE
                cout << "Could not open map view of write file. Error code: " << GetLastError() << endl;
            }
    
            //CLEANUP THE FILE
            UnmapViewOfFile(pvwriteFile);
            UnmapViewOfFile(pvreadFile);
            CloseHandle(writeFileMap);
            CloseHandle(readFileMap);
            CloseHandle(writeFile);
            CloseHandle(readFile);
    
        }
        //ELSE STATEMENT IF CANNOT FIND FILE
        else
        {
            //DISPLAY ERROR MESSAGE THAT NO FILE IS Given
            switch( argc )
            {
                case 0:
                    cout << "No arguments given" << endl;
                    break;
                case 1:
                    cout << "No read file or write file given" << endl;
                    break;
                case 2:
                    cout << "No write file given" << endl;
                    break;
                default:
                    cout << "too many arguments given." << endl;
            }
        }
    
        //cout << "Arg 0 = file to read" << endl;
        //cout << "Arg 1 = file to write to" << endl;
    
        //RETURN A VALUE
        return 0;
    }

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Currently you have it set to not accept any command-line arguments. So don't provide any command-line arguments when you run it.

  15. #15
    Registered User
    Join Date
    May 2011
    Posts
    15
    You dont have to answer this question cuz I know it will sound really stupid but how would I do that? If its dumb just ignore this post

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mapping in C++
    By jack_carver in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2009, 10:00 AM
  2. Height Mapping
    By IdioticCreation in forum Game Programming
    Replies: 17
    Last Post: 10-15-2007, 06:50 PM
  3. Palindrome Program using Memory mapping
    By rrsanch in forum C++ Programming
    Replies: 1
    Last Post: 09-24-2004, 11:49 PM
  4. Texture mapping?
    By rpearson in forum Game Programming
    Replies: 7
    Last Post: 03-04-2004, 10:35 PM
  5. Mapping
    By Scorpion-ice in forum Game Programming
    Replies: 0
    Last Post: 07-02-2002, 01:32 PM