• Advertisement
Sign in to follow this  

odd drag drop on .exe problem

This topic is 4291 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

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
Advertisement
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
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
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
Sign in to follow this  

  • Advertisement