Unexplained INVALID_HANDLE_VALUE from CreateFile()

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 45
Reputation: killdude69 is an unknown quantity at this point 
Solved Threads: 1
killdude69 killdude69 is offline Offline
Light Poster

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #11
May 30th, 2009
Just so you know, the SaveAs works perfect, it is just the Save that is the problem.
Last edited by killdude69; May 30th, 2009 at 8:37 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 83
Reputation: Yiuca is on a distinguished road 
Solved Threads: 15
Yiuca Yiuca is offline Offline
Junior Poster in Training

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #12
May 30th, 2009
Originally Posted by killdude69 View Post
Just so you know, the SaveAs works perfect, it is just the Save that is the problem.
Ah alright, thanks for letting me know I were focusing more on the save as. I just used save & it still works with an absolute path. (In that if choose the full path to the desktop it will still write, any paths that the program doesn't have privilege to save at (for example Program Files, or similar, then it won't work until you've made the program prompt for higher privileges) It seems like the easiest (maybe best, maybe not) way to get around it is to default to a specific path like desktop or documents that is verified to be there. What exactly are you wanting the save to do? I mean obviously you'll want it to save & it seems like the only problem is the actually path defaulting.

Edit: It seems that after you've set an absolute path to save the 1st time, for example C:\Users\<Username>\Desktop, even if you close the program & go back into it, every subsequent save will save to that directory & is essentially working as it should. The only problem comes in with the invalid handle is when you cancel, or the 1st time you save you don't give it an absolute path.
Last edited by Yiuca; May 30th, 2009 at 8:52 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 45
Reputation: killdude69 is an unknown quantity at this point 
Solved Threads: 1
killdude69 killdude69 is offline Offline
Light Poster

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #13
May 30th, 2009
The save is supposed to save the changes to the file if one is already open. If one is not, it will send the command message for SaveAs to prompt a dialog.

I have made a program like this before, and I have never needed any higher priviledge to save in Documents. It has always worked before.

My guess is that the fileName variable (LPSTR fileName = "") is not getting the value, but I am unsure. Because when I use tmp_file for the SaveAs, it seems to work. Also, I am using the same file writing function for Save as I am SaveAs. So the handles are exactly the same, so if it is invalid, the SaveAs should report the same error, but it does not.

So therefor the error cannot be in "SaveText()", it must be in the WM_COMMAND case for CTRL_MENU_FILE_SAVE.

And as to why that is I am still completely clueless.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 83
Reputation: Yiuca is on a distinguished road 
Solved Threads: 15
Yiuca Yiuca is offline Offline
Junior Poster in Training

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #14
May 30th, 2009
Originally Posted by killdude69 View Post
The save is supposed to save the changes to the file if one is already open. If one is not, it will send the command message for SaveAs to prompt a dialog.

I have made a program like this before, and I have never needed any higher priviledge to save in Documents. It has always worked before.

My guess is that the fileName variable (LPSTR fileName = "") is not getting the value, but I am unsure. Because when I use tmp_file for the SaveAs, it seems to work. Also, I am using the same file writing function for Save as I am SaveAs. So the handles are exactly the same, so if it is invalid, the SaveAs should report the same error, but it does not.

So therefor the error cannot be in "SaveText()", it must be in the WM_COMMAND case for CTRL_MENU_FILE_SAVE.

And as to why that is I am still completely clueless.
Alright, I think I see where you're getting at.

So fileName = "", in the Window Procedure it checks if it is "" or not it sends a message for CTRL_MENU_SAVEAS, which calls the function SaveDlg expecting a LPSTR returned. Save Dialog returns the value put into the textbox via Save.File(); Which implementation is in dlgs.h

  1. char* SaveFileDialog::File(void)
  2. {
  3. if(Opened)
  4. {
  5. if(Success)
  6. return FileName;
  7. else
  8. {
  9. if(ShowErrors == true)
  10. {
  11. MessageBox(_Parent, "An error occured or the operation was canceled!", "ERROR", MB_OK | MB_ICONERROR);
  12. }
  13. }
  14. }
  15. }

Assuming Opened & Success are true it returns FileName which ends up returned back in the Windows Procedure in tmp_file, it then calls SaveText with the tmp_file in hand. You're right this seems like a merry go round!

I guess next it's to see if Opened & Success are both evaluating to true. Try shoving a messagebox & a few elses in the SaveFileDialog::File() function, just to see, since if either of them aren't, it'll pretty much skip rest of the function without returning anything. (might be the problem)

To which I will take leave of this problem for the moment here, since I really need some sleep now I would imagine someone else will be able to sort it since there are far better programmers than myself here. So good luck.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 45
Reputation: killdude69 is an unknown quantity at this point 
Solved Threads: 1
killdude69 killdude69 is offline Offline
Light Poster

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #15
May 30th, 2009
Okay, Yuicia.

But actually, Save.File() is only used in the SaveAs, which works perfect.

Save.File() is only used by SaveAs, so that has nothing to do with it.

Here is the outlook if anyone else would like to help me (which seems unlikely since only 1 other person has posted in this thread):

Open: This works, opens the file, shows the text.
SaveAs: This works, Saves the file, no errors returned.
Save: Says the file handle is invalid, even when it is the very same used in SaveAs.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 83
Reputation: Yiuca is on a distinguished road 
Solved Threads: 15
Yiuca Yiuca is offline Offline
Junior Poster in Training

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #16
May 31st, 2009
Originally Posted by killdude69 View Post
Okay, Yuicia.

But actually, Save.File() is only used in the SaveAs, which works perfect.

Save.File() is only used by SaveAs, so that has nothing to do with it.

Here is the outlook if anyone else would like to help me (which seems unlikely since only 1 other person has posted in this thread):

Open: This works, opens the file, shows the text.
SaveAs: This works, Saves the file, no errors returned.
Save: Says the file handle is invalid, even when it is the very same used in SaveAs.
When you use save it checks for isSaved, if that is false then it checks for if (fileName != "") which if it is it sends a message back to Windows Procedure that is the same as if you click Save As, hence you end up with it calling SaveDlg & subsequently Save.File(); later on. (SaveDlg returns the value returned from Save.File())

I would like to note that I don't get an Invalid Handle when I run the program I only get invalid file name which once I've changed to a full path, filename & extention saves just fine even with save. (since it calls save as) if I open a file & click save then I get an error about the file name, directory name or volume label has incorrect syntax & can't be saved. I think that is generated by GetLastError() you'll have to let me know if comparing it with strlen or similar sorts the error, as it may just be mistaken comparison, it usually is something small, silly, easy to miss.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 45
Reputation: killdude69 is an unknown quantity at this point 
Solved Threads: 1
killdude69 killdude69 is offline Offline
Light Poster

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #17
May 31st, 2009
Oh, Yiucia.

This thread is now solved, I decided to completely re-write my save, new, open, and SaveAs code. It was a pain in the ass but it helped. And then when you and ArkM answered my other question, it solved the rest of this one. Thanks again, and for your interest in this question.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 83
Reputation: Yiuca is on a distinguished road 
Solved Threads: 15
Yiuca Yiuca is offline Offline
Junior Poster in Training

Re: Unexplained INVALID_HANDLE_VALUE from CreateFile()

 
0
  #18
May 31st, 2009
Originally Posted by killdude69 View Post
Oh, Yiucia.

This thread is now solved, I decided to completely re-write my save, new, open, and SaveAs code. It was a pain in the ass but it helped. And then when you and ArkM answered my other question, it solved the rest of this one. Thanks again, and for your interest in this question.
I were going to mention that I would have re-wrote it all myself so I knew what were going on, then erased that part & added the last sentence instead. Glad to hear it's been solved.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC