Sign in to follow this  
SelethD

odd drag drop on .exe problem

Recommended Posts

SelethD    456
I was working on a console program, c++ VS.NET with win XP, and i came across an odd problem, so after experimenting, this is what happens
int main(int argc,char* argv[])
{
FILE* fptr = NULL;
fptr = fopen("text.txt","w+b");
fclose(fptr);
return 0;
}
[\source]

When I run the .exe by itself, it generates an empty file TEXT.TXT
When I drap another file onto the .exe, (so that it will be a parameter in argv[]) the program doesnt create the file TEXT.TXT

Any reason why it wont work?
[source\]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
aah. Just some geus.

int main(int argc,char* argv[])
{
Test();
//Rest;

return 0;
}
bool GenerateFile()
{
FILE* fptr = NULL;
fptr = fopen("text.txt","w+b");
fclose(fptr);
return true;
}

Share this post


Link to post
Share on other sites
SelethD    456
Ok, I figured it out.

It was creating the file on both runs, just when clicked on the .exe, it was making it in the folder that contained the .exe

When a file was dragged on the .exe, it was creating the file in my root c:\ directory

So I guess I need the .exe path which is argv[0] appended to the file name

Thanks for the help AP

Share this post


Link to post
Share on other sites
Verg    450
If you need the path/directory of your .exe file at runtime, the global variable _pgmptr may be something you'd want to look at.

_wpgmptr is the (wchar_t *) version.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this