You know how in windows you can drag a file into an exe's icon and the exe will handle the file as it can? How do you do that? I'm using a Windows console application.
Printable View
You know how in windows you can drag a file into an exe's icon and the exe will handle the file as it can? How do you do that? I'm using a Windows console application.
declare main int main(int argc,char ** argv){
argc is one if there is a filename and argv[1] is the filename argv[0] is your owns programs file name Plus post this in the c board not the windows board.
That's how its best done in a console app, but there are a few other options if you want to use a win32 app.....
First you can call on the third param passed to winmain....if you drag and drop a file as you said earlier, you will get the full pathname of the file.....fine so far...Code:#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow){
MessageBox(HWND_DESKTOP,lpCmdLine,"From WinMain",MB_OK);
MessageBox(HWND_DESKTOP,GetCommandLine(),"with GetCommandLine",MB_OK);
return 0;
}
Another more generic method is to use GetCommandLine()....this works for consoles and win 32 apps and gives the name of the calling app as well as the command line, so to get the dropped file name, you need to parse the string (of course take a copy of the string and alter that as opposed to trying to alter the return of this function ;))
The GetCommandLine version is better as it allows you to work in unicode as well as ANSI (getting the params of main or WinMain costricts you to ANSI).......
Thank you. By the way, Canine, the reason I posted it on the Windows board is because I wanted to know how to do it in Windows.
You did say you wanted to do it in a console app. So he was correct.Quote:
Originally posted by CodeMonkey
Thank you. By the way, Canine, the reason I posted it on the Windows board is because I wanted to know how to do it in Windows.
Not all operating systems contain the file parameter option. But let's not fight about such an insignificant suject.
im not sure what you mean:Quote:
Originally posted by CodeMonkey
Not all operating systems contain the file parameter option. But let's not fight about such an insignificant suject.
is an ANSI specification, and except for the formatting of bar[0], is guaranteed. if your compiler doesnt support command line args, um well, get one made some time after the 1940s ;)Code:int main (int foo, char **bar)
Why doesn't getting the cmd line by WinMain param 3 not seem to work on my friend's XP system? Is there a different standard for Windows programming now?
this is the reference point for everyone's statements. console apps use main and not WinMainQuote:
Originally posted by CodeMonkey
blah blah blah ...Windows console application.
Quote:
CodeMonkey: Why doesn't getting the cmd line by WinMain param 3 not seem to work on my friend's XP system?
Quote:
Fordy: The GetCommandLine version is better as it allows you to work in unicode as well as ANSI (getting the params of main or WinMain costricts you to ANSI).......
Thank you all. You may now commence to **** yourselves.