🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10795

Re: Command line parms and dll's

#10795
From: Ed Mulroy [TeamB]
Date: Mon, 15 Mar 2004 18:06
98 lines
3845 bytes
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: <4055f0c4$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4055bde3$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 10:10:37 PST
From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4055bde3$1@newsgroups.borland.com>
Subject: Re: Command line parms and dll's
Date: Mon, 15 Mar 2004 13:06:53 -0500
Lines: 100
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 24.74.175.102
Message-ID: <4055f0c4$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1079374020 24.74.175.102 (15 Mar 2004 10:07:00 -0800)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail