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 -
int WINAPI WinMain(HINSTANCE hInstance, //handle to current instance
-
HINSTANCE hPrevInstance, //pointer to the previous instance
-
LPSTR lpCmdLine, //pointer to the command file
-
int nCmdShow) //show state of the window
-
{
-
//
-
-
HWAVEOUT hWaveOut; //handle to sound card output
-
WAVEFORMATEX WaveFormat; //The sound format
-
WAVEHDR WaveHeader; //Wave header for our sound data
-
-
char Data[BUFFERSIZE]; //sound data buffer
-
-
HANDLE Done; // Event handle that tells us the sound has finished being played.
-
// This is a real efficient way to put the program to sleep
-
//The sound card is processing the sound buffer
-
-
double x;
-
int ii;
-
int i;
-
int FREQUENCY;
-
FILE * pFile; //this is set up to read from a file
-
char string [100]; //this is the file we are reading
-
struct wordd line[20]; //create an array of 20 words
-
char * pch; //from strtok example
-
-
-
//if command line is file
-
if (__argv[1] == "file")
-
{
-
-
pFile = fopen (__argv[2] , "r"); //second argument is filename
-
if (pFile == NULL) perror ("Error opening file");
-
else {
-
fgets (string , 100 , pFile); //get a line from a file
-
pch = strtok (string," "); //split string into token seperated by a space
-
i = 0; // iterator starts at 0
-
while (pch != NULL) // while there is something to split
-
{
-
i++; //this indicates where you are in the loop not used here but for more advanced synths
-
// line[i].word = pch; //put pch in place in the line for this synth freq is first word
-
ii = atoi(pch);
-
pch = strtok (NULL, " "); //grab next word
-
//I will need to have an array of pch to do more paremeters in a synth.. redo the line maybe..
-
playsound(ii);
-
}
-
//ii = atoi(pch); //convert line to a number using atoi
-
// playsound(ii); //play the sound..
-
-
-
//puts (string); prints line I think
-
fclose (pFile);
-
-
}
-
-
}
-
if (__argv[1] = 'file'){};
-
//playsound(int freq)}
-
if (isdigit(__argv[1][1])) //if this is a number play the frequency
-
{
-
i = atoi(__argv[1]);
-
playsound(i);
-
}
-
//if
-
//string = __argv[1];
-
//if (__argv[1] = 'file'){};
-
-
//** Release our event handle **
-
-
return FALSE;
-
-
}
-
-
12 17494
WinMain() is not main().
There is no command line in a Windows program and the arguments on the command line have to be fetched using GetCommandLine( ).
All that argc argv stuff is for native language console applications only.
It seems to compile fine and one of the if's is working it is when I look for a string instead of a charecter it complains.. is there an example of the other somewhere where I compare what I get with your command??? I saw that but didn't understand how to use it (no good examples)
You may need to post your revised code.
GetCommandLine( ) returns an LPTSTR, which is a char* if you are using ASCII and a wchar_t* if you are using Unicode.
Various C functions have been rewritten for Unicode. When you have your peoject set for ASCII you want the ANSI C version and for Unicode you want the ANSI C wide character version. You switch between these two by using the TCHAR mappings (Please read up on this).
The function mappings are http://msdn2.microsoft.com/en-us/library/ms860358.aspx.
Banfa 9,065
Recognized Expert Moderator Expert
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 -
int WINAPI WinMain(HINSTANCE hInstance, //handle to current instance
-
HINSTANCE hPrevInstance, //pointer to the previous instance
-
LPSTR lpCmdLine, //pointer to the command file
-
int nCmdShow) //show state of the window
-
{
-
<snipped>
-
return FALSE;
-
-
}
-
-
The command line is accessable directly in WinMain via the lpCmdLine function argument. I do not think using __argc and __argp is a good idea, I do not believe these are documented/supported features. Thatis you have no guarantee that they will continue to exist from 1 version of the SDK to the next.
You can also create a Windows Console application and that will generate an _tmain(int argc, _TCHAR* argv[]).
Also note that using lpCmdLine does not retrieve the entire command line but only the first argv* portion. The type of lpCmdLine is a LPSTR so you can have only one argument. Usually, this is a file name to be read in that contains the other arguments.
If you are using Unicode, then you have to use GetCommandLine( ). There is a CommandLineToAr gvW() that you can use to recreate the argv string array.
Banfa 9,065
Recognized Expert Moderator Expert
Also note that using lpCmdLine does not retrieve the entire command line but only the first argv* portion. The type of lpCmdLine is a LPSTR so you can have only one argument. Usually, this is a file name to be read in that contains the other arguments.
This is not true, the lpCmdLine is the entire command line concatinated into a single string excluding what would be in argv[0] (i.e. the program name).
Try this program with multiple command line arguments -
#include "windows.h"
-
-
int APIENTRY WinMain(HINSTANCE hInstance,
-
HINSTANCE hPrevInstance,
-
LPSTR lpCmdLine,
-
int nCmdShow)
-
{
-
MessageBox(NULL, lpCmdLine, "Command Line", MB_OK);
-
-
return 0;
-
}
-
The difference between lpCmdLine and GetCommandLine is that lpCmdLine is type LPSTR (for historical reasons) where as lpCmdLine returns LPTSTR. This means that lpCmdLine is always a string of ASCII characters, but GetCommandLine can return a unicode string in a unicode enabled application.
I stand corrected. But:
#include "windows.h"
int APIENTRY WinMain(HINSTAN CE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MessageBox(NULL , lpCmdLine, "Command Line", MB_OK);
return 0;
}
The difference between lpCmdLine and GetCommandLine is that lpCmdLine is type LPSTR (for historical reasons) where as lpCmdLine returns LPTSTR. This means that lpCmdLine is always a string of ASCII characters, but GetCommandLine can return a unicode string in a unicode enabled application.
The MessageBox line only works with 16-bit Windows. MessageBox today is a macro that switches between MessageBoxA (ASCII) and MessageBoxW (Unicode). By default Windows programs are Unicode. That means you need the TCHAR mapping for this to compile. The code should be: -
MessageBox(NULL, GetCommandLine(), TEXT("Command Line"), MB_OK);
-
You can't use lpCmdLine since this is always ASCII. For Unicode you would need to convert this to a Unicode string before passing it to MessageBox. Therefore, the current advice is to always use GetCommandLine( ).
Also, I think there is a typo in your reply:
where as lpCmdLine returns LPTSTR.
I think you mean to say: whereas GetCommandLine( ) returns a LPTSTR. Banfa 9,065
Recognized Expert Moderator Expert
Also, I think there is a typo in your reply:
I think you mean to say: whereas GetCommandLine( ) returns a LPTSTR.
Yes I did, my sloppy writing and coding aside I was just making the point that lpCmdLine points to the entire command line, but is a pointer to an ASCII string.
I saw this as an example. I haven't figured out how to split the line to get an array of what is on the command line (or if it is doing that how it is being done) -
void CCommandLineDlg::OnBtnCmdLine()
-
{
-
// TODO: Add your control notification handler code here
-
char CmdLine[80];
-
char CmdResult[80];
-
-
strcpy(CmdLine, GetCommandLine());
-
sprintf(CmdResult, "%s", CmdLine);
-
m_CommandLine.Format("%s", CmdResult);
-
-
UpdateData(FALSE);
-
}
-
this is from http://www.functionx.com/visualc/Lesson06.htm Sign in to post your reply or Sign up for a free account.
Similar topics |
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)
|
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...
|
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
|
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++...
|
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;
| |
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...
|
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.
|
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...
|
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.
|
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...
|
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...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |