Archived

This topic is now archived and is closed to further replies.

why the hell cant i load this file?

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

you know how all windows programs can accept command lines? and if you create an exe, then drag a file on top of the exe, windows will pass the location of that file as the command line to your app well when i do this, it works great, i can do a nifty MessageBox() to verify that its actually doing that, but when i try to open that file, it wont let me... ive tried both fopen(cmd,"r") and CreateFile(cmd,....); its always gives me an invalid file handle

Share this post


Link to post
Share on other sites
If your creating a console app then you use the main() parameters, cant remember the exact names they are given but they are an int of the total number of command line arguments and an array of strings which contains any files/options you pass to your program on the command line.

In your example you might want to check the first index in the array of arguments for the name of the file you are passing on the command line - FILE *file = fopen(args[0],"r")

EDIT: with windows pograms - those which contain WinMain(), you might want to look into the paramter LPSTR lpCmdLine, the name kind of gives it away really

here's an example main() with the parameters i mentioned:
int main(int argc, char *argv[])




[edited by - Spudder on November 12, 2003 9:02:49 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why the hell cant people ask a question without saying hell?

Share this post


Link to post
Share on other sites
Fireking, you might want to tell us if you''re doing a Console app or a Windows app. Just to help us help you. (I''m betting on Windows, but just to be sure tell us anyway, okay?)

And I do suspect something, I remember experimenting with this and finding that the ''active directory'' varies between starting a program by double-click, and starting it with a drag-and-dropped file on it. I invite you to check what directory is active, look exactly at what info you got in your main() params, etc etc.

If it''s like me, you''ll find out that current directories vary a bit too much for ease of use. Hope this helps.

Share this post


Link to post
Share on other sites
Call GetLastError() to find out why CreateFile() is failing. However, if you''re trying to open a file that has been dragged and dropped on your app then try using OpenFile() since it already exists.

Share this post


Link to post
Share on other sites