|
First off, I'm not sure if I'm quite in the right forum or not, so just let me know if I should post elsehwere. With that said...
I'm brand new to C++ and am trying to wrap my brain around something. I know that I can use a MAIN function in a .CPP file and use it to grab command line arguments. I'm trying to add this feature to an existing clump of code we've got at work (I'm trying to expand my skills, and it's a small utility we techies use only occasionally). Anyway, I can't figure out how to use a MAIN function if there isn't already one (I can make it work in a brand new test project just fine). My current attempt to tweak the code sort of looks like this:
#include "stdafx.h"
#include ...a few other files.....
class CApp : public CWinAppEx
{
public:
CApp();
public:
virtual BOOL InitInstance();
};
extern CApp theApp;
int main(int argc, char *argv[])
{
MessageBox(NULL, L"This should display first, but doesn't currently show up at all.", NULL, NULL);
}
CApp::CApp()
{
MessageBox(NULL, L"This should display second, but currently shows up first.", NULL, NULL);
}
CApp theApp;
BOOL CApp::InitInstance()
{
MessageBox(NULL, L"This should display third, but currently shows up second.", NULL, NULL);
...does other stuff here...
}
So what do I need to do to use MAIN correctly to grab the command line arguments?
Thanks!
|
|
|
|
|
|
You have code for a Windows application there. And it also looks like it is using MFC. You won't find a main(), nor will you need to. Odd, though is that you have 'theApp' declared twice. That's definitely not a good start.
There are methods of the CWinAppEx class that can be called in InitInstance to assist with command line handling.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
As others have said, you either have main() or you have your WinApp (theApp ) but not both. And definitely not two instantiations of theApp .
The command line arguments can be accessed during your InitInstance() function by looking at the m_lpCmdLine data member of your class.
There are a number of classes / functions that can help you parse it in the argc/argv style you're accustomed to, links are in earlier answers to this question.
|
|
|
|
|
|
in your CWinApp:InitInstance, you should be able to access the __argv and __argc variables.
|
|
|
|
|
I did not know that, been tokenizing m_lpCmdLine myself. +5 for the info.
|
|
|
|
|
Hi ,
How can we represent structure bitfiled in the UML Model??
|
|
|
|
|
|
If i have the following case,
Struct Mode
{
union
{
unsigned char MSB;
struct
{
unsigned char a:2
unsigned char b:3
unsigned char c:3
}
}
}
How to model the struct "Mode" in the class diagram?
|
|
|
|
|
[ Here ] is a good UML primer.
#include <iostream>
using namespace std;
class c_Mode
{
public:
union
{
unsigned char MSB;
struct
{
unsigned char a:2;
unsigned char b:3;
unsigned char c:3;
};
};
} ;
struct s_Mode
{
public:
union
{
unsigned char MSB;
struct
{
unsigned char a:2;
unsigned char b:3;
unsigned char c:3;
};
};
} ;
int main()
{
c_Mode clsMode;
clsMode.a=0;
clsMode.MSB=0;
s_Mode mode ;
mode.a=0;
mode.MSB=0;
return 0;
}
|
|
|
|
|
|
|
People Hi!People, prompt why VC ++ doesn't open title files, can where it is necessary to adjust?
It is all to be in one folder, and doesn't want to open.
|
|
|
|
|
Your question is not very clear, but if you are having trouble accessing files in your project then check that the location property is correct.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Ok! in my project there is two file-first main.cpp and main.h,and i am using command #nclude"main.h",But in the с++ editor the error that can't open this file Both files are in one directory
|
|
|
|
|
What do you mean "can't open"? If both files are in the correct directory then the editor will find them. You must have some other problem that is preventing it from locating the file. I presume the word "#nclude " above is a simple typo here only and not in your source file.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
PeLeg89 wrote: #nclude
Try #include
==============================
Nothing to say.
|
|
|
|
|
If your editor can't find a file, it means either:
0. File doesn't exist.
1. Path is not specified correctly in the include (if using entire path).
2. Path is not part of the project library/include directories (if using <> ).
3. I believe I've also seen this occur if the file is not part of the project (although don't quote me on that one, don't quite remember)
|
|
|
|
|
Thank all,you helped me ,I think this is 3 item
|
|
|
|
|
Great
|
|
|
|
|
Can someone assist me how to read/write physical memory location from IP address?
Thanks.
|
|
|
|
|
User code can just access virtual memory (i.e. it doesn't know the physical address is accessing).
fingerss5 wrote: from IP address
If you mean: "from a remote PC" then you have to write a client-server application for the purpose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
fingerss5 wrote: Can someone assist me how to read/write physical memory location from IP
address?
Just what do you mean? An IP address has nothing to do with memory.
If you mean on a remote machine, then say so. And the other posters comments are entirely valid if that is the case.
==============================
Nothing to say.
|
|
|
|
|
[ This ] talks about Shared memory access permissions on Windows.
Maybe [ this ] article on Memory-mapped files might help but it applies to XP, not Vista/Windows 7.
("Memory-mapped files allow a file on disk to be associated with an address space. Once this mapping is done the data in the file can be accessed as if the file was in memory." )
MSDN has lots on Memory-mapped files, google "Sharing Memory Over Networks" and/or "Memory-mapped files".
|
|
|
|