Strange Behaviour in fopen&drag/drop

Hi all people
Yesterday i was making a simple little program that reads file names by dragging them over the program icon and releasing the mouse button

i expect to receive the file name on "argv[1]", and open it with a simple fopen();

so the command received by the program should be, i think, C:\program.exe "C:\randomfile.txt"

now the question is, if i do that by the command line it goes without problems.
but if i drag&drop files on the program, it crashes when i try to open another second file with fopen();. i'm a beginner and i don't know why

i tried with a very very simple program as that:

1
2
3
4
5
6
7
8
#include <stdio.h>

int main(int argc, char * argv[])
{
FILE * File=fopen("file.txt", "rb");
fclose(File);
return 0;
}



i just tryed it, and if i run it without arguments, i get no errors. no errors even if i give program.exe "ramdomfile.txt".
but if i drag files over, it crashes every time, apparently because i open a file with fopen()

does anyone here knows the error?
Last edited on
When you drag a program from the Windows shell to an icon, the shell starts the app under that icon and passes the dragged filename(s) as argument(s). So when the app starts, it can check the args passed to it.

When you drag a program from the Windows shell to an application window, the shell passes the dragged content using the drag/drop protocol it uses. To receive the content, you have to obey the protocol.

http://msdn.microsoft.com/en-us/library/bb776905%28v=VS.85%29.aspx
Thank You for your help :D
Topic archived. No new replies allowed.