Article View: borland.public.cppbuilder.nativeapi
Article #10798Re: Command line parms and dll's
From: p Anders
Date: Mon, 15 Mar 2004 19:17
Date: Mon, 15 Mar 2004 19:17
104 lines
4224 bytes
4224 bytes
thanks - that was a lot of help
"Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> wrote in message
news:4055f0c4$1@newsgroups.borland.com...
> The variables _argv and _argc are established by the startup code and
> for code in the DLL they refer to the startup code for the DLL, not
> for the executable.
>
> Remember that the DLL has no command line parameters.
>
> If the DLL and EXE are both dynamic linked then they share some of the
> runtime library. The _argc and _argv elements appear to be found as
> those from the EXE's command line . A call to the Windows API
> function GetCommandLine returns the command line for the process.
>
> If the DLL and EXE are static linked then there are no _argv style
> args, but GetCommandLine's return value remains the same.
>
> Try it for yourself. Cut and past these 3 files into a directory by
> themselves and give teh command MAKE
>
> -------prog.cpp--------
> #include <windows.h>
>
> __declspec(dllimport) void DoIt();
>
> int main()
> {
> DoIt();
> return 0;
> }
> -------dll.cpp---------
>
> #include <windows.h>
> #include <stdio.h>
>
> BOOL WINAPI DllEntryPoint(HINSTANCE, DWORD, LPVOID)
> {
> return TRUE;
> }
>
> #include <dos.h>
>
> __declspec(dllexport) void DoIt()
> {
> for (int i = 0; i < _argc; ++i)
> printf("%2d \"%s\"\n", i, _argv[i]);
>
> printf("\"%s\"\n", GetCommandLine());
> }
> --------makefile--------------
> # Sources: prog.cpp for EXE's dll.cpp for DLL's
> #
> # Static: progSTAT.exe dllSTAT.exe and dllSTAT.lib
> # Dynamic: progDYN.exe dllDYN.exe and dllDYN.lib
>
> done : progSTAT.exe progDYN.exe
> @echo .
> @echo Results when static linked
> progSTAT cmd_arg_1 cmd_arg_2 cmd_arg_3
> @echo .
> @echo Results when dynamic linked
> progDYN cmd_arg_1 cmd_arg_2 cmd_arg_3
>
>
> # Rules to build the static linked version
> progSTAT.exe : prog.cpp dllSTAT.lib
> bcc32 -WC -c -q prog dllSTAT.lib
> ilink32 /Tpe/ap/Gn/c/x/q c0x32 prog,progSTAT,,dllSTAT import32 cw32
>
> dllSTAT.lib : dll.cpp
> bcc32 -WD -c -q dll
> ilink32 /Tpd/ap/Gn/c/x/q c0d32 dll,dllSTAT,,import32 cw32
> implib -c dllSTAT.lib dllSTAT.dll
>
>
> # Rules to build the dynamic linked version
> progDYN.exe : prog.cpp dllDYN.lib
> bcc32 -WCR -c -q prog dllDYN.lib
> ilink32 /Tpe/ap/Gn/c/x/q c0x32 prog,progDYN,,dllDYN import32 cw32i
>
> dllDYN.lib : dll.cpp
> bcc32 -WDR -c -q dll
> ilink32 /Tpd/ap/Gn/c/x/q c0d32 dll,dllDYN,,import32 cw32i
> implib -c dllDYN.lib dllDYN.dll
> -----------------------------------
>
> . Ed
>
> > p Anders wrote in message
> > news:4055bde3$1@newsgroups.borland.com...
> >
> > I am using _argc and _argv to retrieve command line parameters.
> > These don't seem to work in a dll - maybe this makes sense but
> > I'm not really familiar with dll's.
> >
> > Isn't argc and argv ALWAYS guaranteed to at least contain the
> > name of the program itself???????
> >
> > Can someone tell me, 1) does this make sense? Is there another
> > way to get command line parms in a dll? and 2) what I really need
> > from the command line parms is the name of the program itself.
>
>
Technical Details
Message-ID:
<40560134$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4055bde3$1@newsgroups.borland.com> <4055f0c4$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ba03626f392813af X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-15 11:32:57 PST Reply-To: "p Anders" <paul.anderson@jhuapl.edu> From: "p Anders" <paul.anderson@jhuapl.edu> Newsgroups: borland.public.cppbuilder.nativeapi References: <4055bde3$1@newsgroups.borland.com> <4055f0c4$1@newsgroups.borland.com> Subject: Re: Command line parms and dll's Date: Mon, 15 Mar 2004 14:17:09 -0500 Lines: 106 Organization: JHU/APL X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 128.244.21.78 Message-ID: <40560134$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1079378228 128.244.21.78 (15 Mar 2004 11:17:08 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail