From: Mumit K. <khan@NanoTech.Wisc.EDU> - 2001-01-31 06:52:11
|
On Tue, 30 Jan 2001, Appaiah Kumaraswamy wrote: > Hello! I am a novice programmer, just programming for fun. I have been > using MinGW for a long time, and while browsing the headers, I found > this cool feature in stdlib.h. Two variables, _argv and _argc are > defined there, which allow non-console, ie. Windows apps to use the dos > "main ()" style argument handling. I think it's much better than using > the LPSTR variable in WinMain. If you're using main(), a better way to handle this the portable way -- use the argv and argc arguments passed to main by the underlying OS. #include <stdio.h> #include <stdlib.h> int main (int argc, char *argv[]) { int i; for (i = 0; i < argc; i++) printf ("argv[%d] = %s\n", i, argv[i]); exit (0); } instead of using non-portable schemes like _argv and _argc. Guaranteed to work on all "non-freestanding" or "hosted" implementations. Freestanding implementations include embedded systems, like your toaster or refrigerator of the future, that may not have such facilities. > This thing also lets me get the module file name, by accessing _argv > [0]. But there's one gotcha, about which I would like to ask: > > I have made an application in, say D:\CC++\, by name abc.exe, which > prints the value of _argv [ 0 ]. Now, if I GCC 2.95.2 (CRTDLL), to > compile the application, then the printout is: > D:\CC__~1\abc.exe > > but if I use GCC 2.95.2-1 (MSVCRT), the output is: > D:\CC++\abc.exe > > Does this show that the problem is in CRTDLL.DLL (outdation, maybe?), or > am I doing something wrong? Yes, CRTDLL is obsolete and MS is not going to update it other than possibly fixing major bugs. MSVCRT is the way to go. Regards, Mumit |