7 Replies - 1579 Views - Last Post: 06 October 2012 - 12:47 PM Rate Topic: -----

#1 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 08-September 11

Read command line parameters in VC++

Posted 05 October 2012 - 06:13 AM

I am using Visual C++ 2010 Express to create a Win32 project. So, my main program starts

int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPTSTR lpCmdLine,
                       int nCmdShow)



I want to be able to set some parameters on the command line when the program is executed, probably from a shortcut with the appropriate values set there.
However, when I look at the last two items nCmdShow is 1, and lpCmdLine is blank.
I have tried using GetCommandLine and that has also returned a blank string.

I have tried adding a parameter to the properties of the shortcut but this has made no difference.

I have even tried through a cmd window and moving to the program's home directory and adding a parameter there. Again, no luck.

The CommandLinetoArgvW function does not seem to exist in VC++ 2010 Express. The documentation says:
This function only works with the Unicode/Wide character set and there seem to be no CommandLineToArgvA ANSI equivalent function.

Where do I go now?

Is This A Good Question/Topic? 0
  • +

Replies To: Read command line parameters in VC++

#2 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 773
  • View blog
  • Posts: 2,291
  • Joined: 20-March 10

Re: Read command line parameters in VC++

Posted 05 October 2012 - 06:37 AM

Hi,

This should be moved to C/C++ forum

That said you can access CommandLineToArgvW function in Express
by downloading the Windows 7 SDK and setting your platform Toolset to Win7 SDK
or by copying all the includes and libs from the Win7 VC directory to Express's VC directory.

or you can set the whole program to use Multi Byte Character set and use this as an entry point

int CALLBACK WinMain(
  _In_  HINSTANCE hInstance,
  _In_  HINSTANCE hPrevInstance,
  _In_  LPSTR lpCmdLine,
  _In_  int nCmdShow
);



Then just use GetCommandLine function


Best Wishes

Snoopy.

This post has been edited by snoopy11: 05 October 2012 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

#3 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 08-September 11

Re: Read command line parameters in VC++

Posted 05 October 2012 - 09:54 AM

So I've downloaded the SDK file and run it and get the message shown in the attachment.
Useful?

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,516
  • Joined: 23-August 08

Re: Read command line parameters in VC++

Posted 05 October 2012 - 10:39 AM

Moved to C/C++
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5310
  • View blog
  • Posts: 27,210
  • Joined: 10-May 07

Re: Read command line parameters in VC++

Posted 05 October 2012 - 10:48 AM

Isn't tWinMain specific to Tubro C++ & not Visual C++?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3574
  • View blog
  • Posts: 11,114
  • Joined: 05-May 12

Re: Read command line parameters in VC++

Posted 05 October 2012 - 12:01 PM

_tWinMain() is in tchar.h for Visual Studio C++. It let people have a single source base for UNICODE builds on Windows NT and later, and ANSI/Multibyte builds for Win9x.

tWinMain(), if I remember correctly, is for Turbo C++ when they started supporting Win3.x programming.
Was This Post Helpful? 1
  • +
  • -

#7 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 773
  • View blog
  • Posts: 2,291
  • Joined: 20-March 10

Re: Read command line parameters in VC++

Posted 05 October 2012 - 08:25 PM

View Postnorman1312, on 05 October 2012 - 04:54 PM, said:

So I've downloaded the SDK file and run it and get the message shown in the attachment.
Useful?



It looks as if you have had a problem with the download,

It's a big download so plenty can go wrong try redownloading it

Do you have the .net framework downloaded ?

I guess you must if you are running express

Did you download the correct sdk ?

see link below

http://www.microsoft...ls.aspx?id=8279
Was This Post Helpful? 0
  • +
  • -

#8 norman1312  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 08-September 11

Re: Read command line parameters in VC++

Posted 06 October 2012 - 12:47 PM

That's what I used. This file is 498K. I ran that, it appeared to extract some files and almost immediately after that the error popped up.
There's not much I can do about that, or is there?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1