Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2004

Tip: Looking for answers? Try searching our database.

Read variables through EXE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ashton - 10 Sep 2004 21:49 GMT
Sorry for the confusing topic, I wasn't sure how to word this exactily.

I have a program that needs to read a variable in from the outside.
Specifically, the program will be run like this:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Exec("myProgram.exe 123456")
end sub

myProgram.exe is a VC++ application
123456 is a variable I want to be able to read into this VC++ application.

Any advice on how to do this would be greatly appreciated. I tried looking
around for an answer but I could not find a decent reference
Peter van der Goes - 10 Sep 2004 22:16 GMT
> Sorry for the confusing topic, I wasn't sure how to word this exactily.
>
[quoted text clipped - 10 lines]
> Any advice on how to do this would be greatly appreciated. I tried looking
> around for an answer but I could not find a decent reference

Perhaps this short article on an alternate form of the main() header will
help:

"In many example programs, the parameters to main are left off (they are
optional) and so you may have never been exposed to the complete use of
main().

The full syntax for main is:

  int main(int argc, char* argv[]);

....where argc is the "argument count" ("argument" applying to command-line
arguments) and argv is an array of argc elements, each a pointer to a
command line argument (as a string, of course).  The first element is
always the program's own name.

For example, if you had a program called FOO.EXE that you had started by
entering...

   FOO /a /b "my argument"

....on the command-line, you could access the command-line arguments in
your code like so...

  int main(int argc, char* argv[])
     {
     int   iArgCount = argc;     // equal to 4
     char* pszProg   = argv[0];  // points to something like "FOO.EXE"
     char* pszArg1   = argv[1];  // points to "/a"
     char* pszArg2   = argv[2];  // points to "/b"
     char* pszArg3   = argv[3];  // points to "my argument"

          .
          .
     }

If you need access to the arguments later in your program, you can either
copy them or just keep pointers to them (as the parameters to main() must
necessarily remain valid for the entire course of your program's execution).
Part of the way argv[] works is that anything enclosed in quotes (like
"my argument" in the above example) is treated as a single argument. "

Signature

Peter [MVP Visual Developer]
Jack of all trades, master of none.

ashton - 11 Sep 2004 01:15 GMT
Just what I needed, thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.