473,788 Members | 2,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

command line options in winmain with __argv

46 New Member
I want to compare what I get on the command line in winmain with an if statement.. I am getting a beginers error but I don't have an example to use to fix it.. cannot convert from 'const int' to 'char *' in this line if (__argv[1] = 'file'){};
I am very lost with this error and any help would be apreaceated

Expand|Select|Wrap|Line Numbers
  1. int WINAPI WinMain(HINSTANCE hInstance, //handle to current instance
  2.                    HINSTANCE hPrevInstance, //pointer to the previous instance
  3.                    LPSTR lpCmdLine,  //pointer to the command file
  4.                    int nCmdShow)     //show state of the window
  5. {
  6.     //
  7.  
  8.     HWAVEOUT hWaveOut;  //handle to sound card output
  9.     WAVEFORMATEX WaveFormat;  //The sound format
  10.     WAVEHDR WaveHeader;       //Wave header for our sound data
  11.  
  12.     char Data[BUFFERSIZE];  //sound data buffer
  13.  
  14.     HANDLE Done;  // Event handle that tells us the sound has finished being played.
  15.                   // This is a real efficient way to put the program to sleep
  16.                     //The sound card is processing the sound buffer
  17.  
  18.     double x;
  19.     int ii;
  20.     int i;
  21.     int FREQUENCY;
  22.     FILE * pFile; //this is set up to read from a file
  23.     char string [100]; //this is the file we are reading
  24.     struct wordd line[20]; //create an array of 20 words
  25.     char * pch; //from strtok example
  26.  
  27.  
  28.     //if command line is file
  29.     if (__argv[1] == "file")
  30.     {
  31.  
  32.           pFile = fopen (__argv[2] , "r"); //second argument is filename
  33.           if (pFile == NULL) perror ("Error opening file");
  34.           else {
  35.               fgets (string , 100 , pFile); //get a line from a file
  36.               pch = strtok (string," "); //split string into token seperated by a space
  37.               i = 0; // iterator starts at 0
  38.               while (pch != NULL) // while there is something to split 
  39.               {
  40.                   i++; //this indicates where you are in the loop not used here but for more advanced synths
  41.             //      line[i].word = pch; //put pch in place in the line for this synth freq is first word
  42.                   ii = atoi(pch);
  43.                   pch = strtok (NULL, " "); //grab next word
  44.                   //I will need to have an array of pch to do more paremeters in a synth..  redo the line maybe..
  45.                   playsound(ii);
  46.               }
  47.               //ii = atoi(pch); //convert line to a number using atoi
  48.              // playsound(ii);      //play the sound..
  49.  
  50.  
  51.               //puts (string); prints line I think
  52.               fclose (pFile);
  53.  
  54.    }
  55.  
  56. }
  57.     if (__argv[1] = 'file'){};
  58.          //playsound(int freq)}
  59.     if (isdigit(__argv[1][1])) //if this is a number play the frequency
  60.     {
  61.          i = atoi(__argv[1]);
  62.          playsound(i);
  63.     }
  64.     //if 
  65.     //string  = __argv[1];
  66.     //if (__argv[1] = 'file'){};
  67.  
  68. //** Release our event handle **
  69.  
  70.  return FALSE;
  71.  
  72. }
  73.  
  74.  
Nov 22 '07
12 17498
weaknessforcats
9,208 Recognized Expert Moderator Expert
void CCommandLineDlg ::OnBtnCmdLine( )
{
// TODO: Add your control notification handler code here
char CmdLine[80];
char CmdResult[80];

strcpy(CmdLine, GetCommandLine( ));
sprintf(CmdResu lt, "%s", CmdLine);
m_CommandLine.F ormat("%s", CmdResult);

UpdateData(FALS E);
}
I hope you understand that this is ASCII code and most Windows code is Unicode. You are not using the TCHAR mappings.
Expand|Select|Wrap|Line Numbers
  1. void CCommandLineDlg::OnBtnCmdLine() 
  2. {
  3.     // TODO: Add your control notification handler code here
  4.     TCHAR CmdLine[80];
  5.     TCHAR CmdResult[80];
  6.  
  7.     _tcsncpy(CmdLine, GetCommandLine());
  8.     _stprintf(CmdResult, TEXT("%s"), CmdLine);
  9.     m_CommandLine.Format(TEXT("%s"), CmdResult);
  10.  
  11.     UpdateData(FALSE);
  12. }
  13.  
Plus, strcpy, and sprintf are deprecated by Microsoft. You are supposed to use the newer safe _s versions.

Plus you have a hard-coded 80 that is a crash waiting to happen.
Nov 27 '07 #11
eric dexter
46 New Member
Those are good things to know certainly but I am using a compiler that was made by microsoft circa 2001 (and a borland c compiler from the same era).. It also doesn't realy answer the question as far as how to make that an array of strings from the command line. I am having a hard time finding an example on the internet.. The code I am trying to add a command line is here (if that is helpfull and it may not be)

http://dexrowem.blogsp ot.com/2007/11/command-line-synth.html
Nov 29 '07 #12
weaknessforcats
9,208 Recognized Expert Moderator Expert
You will have to post your code. I don't navigate to to other sites.

Remember, GetCommandLine fetches the entire command line as one string.
You will have to parse that string looking for the data that constitues your strings. Then you:
1) aallocate memory for the string as a char array
2) copy data from the command line to your allocation
3) add the address of the string to an array of char* that is you array of strings.
Nov 29 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2781
by: Edvard Majakari | last post by:
Hi, I was wondering what would be the most elegant way for creating a Python class wrapper for a command line utility, which takes three types of arguments: 1. options with values (--foo=bar) 2. boolean options (--squibble) 3. data lines (MUNGE:x:y:z:frob)
7
6037
by: Ken Innes | last post by:
I am trying to write a little program that can be run as a Windows program or as a command line program. I'm really not sure the best way to do this, so what I came up with so far was to check for command line parameters (code shown below). This works, except that printf()'s don't display anything. Is there a better way to do this? WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int pszCmdLine) { if(ParamStr(5)!="") { main1(); //command...
2
2659
by: Dr. Laurence Leff | last post by:
How does not compile a Windows API and a Windows MFC program from the command line with Visual.net. (I can do the former, at least, with Visual Studio by creating a "Win32 Project.") However, I tried the same thing on the command line. (In the days of Visual C++ 4.0 through Visual C++ 6.0, I had some make files and stuff that did this. So, I typed CL hellowin.C
5
5832
by: jlea | last post by:
I'm trying to pass a filename, obtained with using the fileName property from the OpenFileDialog, as a application parameter in Process.StartInfo.Arguments and run a MFC/C++ application using the Start method. When I hardcode the application parameter such as "/name=c:\\myFile.txt" all is well in the C++ application. When I use the fileName property to build the parameter, the string becomes @"/name=c:\myFile.txt" which makes the C++...
2
3129
by: Nagesh | last post by:
hi, I am want copy the command line arguments from szCmdLine of WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) into **char cmdLineParameter. So that I can use cmdLineParameter in other functions. If any body knows pls help me I am trying the following code sample: char **cmdLineParameter;
4
5007
by: Bit byte | last post by:
I have a project that I normally build (without problems) from the DevStudio IDE. However, I have embarked on automating all my builds (this test project being one of several). The project creates a DLL. I am able to build the project without any probs in the IDE, however - when I build the project from the command line (using the same options shown in the 'Command line' node in the 'Project Settings' dialog box), I get the following...
8
3519
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the individual swithces do not get passed to option parser.
3
10325
by: jlw16 | last post by:
Hello, I’m trying to use my vbs script to get a command line argument for a file which will need to be opened through QuickTestPro. Below are the commands I’m using: Dim qt_file 'As String -> If I don’t comment out the As String, I get an “Expected end of statement” error – is this correct?? qt_file = Command -> This doesn’t appear to be correct – when I echo out qt_file it’s null qtApp.Test.DataTable.Import qt_file ' Import data...
51
4162
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under Command Prompt or Browser or some other application? Ojas.
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10370
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.