|
just use __argc and __argv. they behave exactly like the C argc and argv parameters.
run down argv and parse the command line parameters yourself. or, use one of the many command line parsing classes around: here's one
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
if ( (argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/')) )
{
if ( _stricmp( "export", argv[1]+1 ) == 0 )
{
CmdExport();
}
else if ( _stricmp( "import", argv[1]+1 ) == 0 )
{
CmdImport();
}
exit(0);
}
}
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
You have to ignore my ignorance but I am reasonably inexperienced in this particular area.
I am working in a Dialog application in the InitInstance function therefore the old style isn't as appropriate how can it be modified. I understand that __argc and _targc are appropriate in this case. Is this true and how does it alter from what you have already posted.
Thanks for your help
|
|
|
|
|
this isn't specific to dialog apps (works fine in doc/view, too):
BOOL CThumb7App::InitInstance()
{
...
if (__argc > 1)
{
firstParam = __argv[1];
}
else
{
firstParam="";
}
...
}
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I think I am slowly getting it.
I have the following options of:
Program is called "Registry Backup.exe"
Export or Import (/Export or /Import)
Local Machine file or Current User file ( LM: or CU: )
Then the path to which it will be exported or imported (arg1)
So I could have a command line of:
Registry Backup.exe /Export LM: "C:\Sofware\Registry.dat"
The path would have to be inclosed in speech marks, correct?
How would your example be modfied in such a scenerio?
|
|
|
|
|
any parameter with spaces in it must be in quotes, otherwise, the shell will break it into multiple parameters. i'm not sure what happens if your application name contains spaces.
assuming the command line you gave, this is the contents of __argv:
__argv[0] = application name
__argv[1] = "/Export"
__argv[2] = "LM:"
__argv[3] = "C:\..."
so, grab __argv[1], test it for "/Export" or "/Import" and proceed accordingly.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I am attempting to write a C library of routines for my DVD player. (It talks over a serial port.) I want the library as portable as possible, so I'm attempting to do it in C. I know it'd be alot easier for me to do it with classes, but as far as I'm concerened, C++ is out of the question.
I can successfully compile the header below with it's .c file. The problem comes when other C++ modules (I'm trying to use the C library in an MFC app) #include the header. The compiler chokes on the first paranthesis inside the struct definition. I'm thinking it's something having to do with switching into C++ mode.
The whole reason why I'm doing this is because I don't want the user to have to mess with a buffer. All they need to provide are callbacks for Open, Close, Read, and Write (reguarldess if they are using J.P. Naughter's serial wrappers, raw win32 api, or Unix file i/o) of the serial port library and users can do something simple like: DVDPlayer.Execute(PLAY); and not have to worry themselves with formatting, writing and returning the response to me for parsing. This way, it can all be handled internally. And in C.
[ccode]
#pragma once
int DVF07Error(struct DVF07*);
void DVF07StoreTOC(struct DVF07*, struct toc_type*);
void DVF07StoreTrack(struct DVF07*, struct toc_type*, int);
void DVF07TraceTOC(struct toc_type*);
int DVF07Format(struct DVF07*, int, int);
int DVF07Execute(struct DVF07*, int, int);
int DVF07ReturnedInt(struct DVF07*);
int DVF07SizeofBuf(struct DVF07*);
typedef struct DVF07{
/* in c++ files, when this is #included, the ( of int (*Error is */
/* where the compiler chokes, but it compiles fine when */
/* the .c file #includes it */
int (*Error)(struct DFV07 *this);
void (*StoreTOC)(struct toc_type*, struct *toc_type);
void (*StoreTrack)(struct toc_type*, int i);
void (*TraceTOC)(struct toc_type *toc);
int (*Format)(struct DVF07 *this, int, int);
int (*Execute)(struct DVF07 *this, int, int);
int (*ReturnedInt)(struct DVF07 *this);
int (*SizeOfBuf)(struct DVF07 *this);
/* user provided routines below */
int (*Write)(struct DVF07 *this);
int (*Read) (struct DVF07 *this);
int (*Open) (struct DVF07 *this, int port);
int (*Close)(struct DVF07 *this);
char buf[256];
} DVF07_Type;
[/ccode]
|
|
|
|
|
I see one potential problem with that line: "this" is a C++ keyword. Could that be the problem? What happens if you comment that line?
"Harland Pepper, would you stop naming nuts" - Harland Pepper
|
|
|
|
|
I don't think so. I've compiled code before using 'this' in C. I think it only is a problem when __cplusplus is defined. And in this case, it is not -
I hope
|
|
|
|
|
#ifdef __cplusplus<br />
extern "C" {<br />
#endif<br />
<br />
<br />
#ifdef __cplusplus<br />
}<br />
#endif
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks! this worked after I cleaned up a a few issues...
|
|
|
|
|
Anyone know how I can find what the path to the "My Documents" directory is please?
|
|
|
|
|
Use the SHGetSpecialFolderLocation function with the CSIDL_PERSONAL option.
|
|
|
|
|
Thanks!
|
|
|
|
|
hi!!!
can you help me???I've a matter with my MFC because when I press a button "New",which is already in a MFC,it doesn't get on...Debugger of Visual C++ send me to the line:
"ASSERT(::GetWindowLong(hWnd Ctrl,GWL_STYLE & WS_STYLE));"
and it stop to a line of my programm which is:
if(mListX.FindString(0,lNewExplosif->NameX()) EQ LB_ERR))
Do you know what does it mean????
foed in france
|
|
|
|
|
I am going through some code, and I noticed the following:
{snip}
double x[SIZE];
//x[] is filled
foo(x-1);
//where foo takes double data[] as argument
{snip}
What exactly is being passed here? What does subtracting an integer from an array do?
Thanks,
Ryan
|
|
|
|
|
When u reduce n from an array address (here x), the address will reduce to x - (n * sizeof(the type of x))
In this case u r reducing 1 from the double array address x. So, the new address will be educed by 8 bytes, since size of double is 8 bytes.
Go through the below given sample.
void foo(double* x)
{
printf("%f", *x);
}
void main()
{
double x[] = {1,2,3};
foo(x+1);
}
See the output to convince urself.
|
|
|
|
|
The value x is treated as a pointer to the start of the array so it is pointer arithmetic that is being used. The code is passing a pointer to one element before the start of array x, i.e. x[-1].
I would guess that one of the algorithms in the function expects the data to be in x[1..N]. This often occurs when the algorithm was originally developed for a different language (e.g. Fortran program where lower bounds are usually 1), rather than C or C++ where the lower bound is zero.
So they may be offsetting the array to use the original algorithm.
void foo(double y[SIZE])
{
// y[1] is now equivalent to x[0]
}
p1514
|
|
|
|
|
VC++ doesn't bother if it is an address pointing to start of an array or not. It knows that x is a pointer to double and size off double is 8 bytes. So, if u increment or decrement the pointer, the address will be recuced as multiple of 8 (for double).
But there is a chance of exception in the case of x[-1], since the location x-1 is not reserved for x and that location may not be free.
|
|
|
|
|
Hi,
I like to know if anyone knows how to have the child window of an MDI application maximized at the start of the application...
thanks
ehsan
Ehsan Behboudi
|
|
|
|
|
In the OnInitialUpdate() function of your application's View, write the following code
GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);
For example, if the view class is CMyView, then do as follows.
void CMyView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);
}
Happy coding...
Rejeesh
|
|
|
|
|
it didn't work,,
i added the OnInitialUpdate fucntion from the wizard,,but it didn't work???
Ehsan Behboudi
|
|
|
|
|
It must work. I have done it. Do as follows.
1. Make a MDI project.
2. Using class wizard, add a new OnInitialUpdate() function in ur view class.
3. Add as follows,
void CTestView::OnInitialUpdate()
{
CView::OnInitialUpdate(); //Added by wizard
GetParentFrame()->ShowWindow(SW_SHOWMAXIMIZED);//Added by me
}
4. Compile and run the code.
5. It must work.
|
|
|
|
|
Im trying to understand virtual functions but cant see what they do. I presumed this would
be the situation I would use them in where I have two identical functions with same prototypes
which do different things, however this works as expected - outputs the base class cout, and
then the derived class one.
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
void vfunc() { cout << "Derived class vfunc.\n"; }
protected:
unsigned int numBullets;
};
int main() {
CBadGuy a;
CSoldier b;
a.vfunc();
b.vfunc();
return 0;
}
I cant understand why this works though, I thought that the funciton vfunc() would be ambigous when
I refered to it through object b as sureley this contains its own vfunc as well as the derived one.
Is it the case that I am simply "overloading" the b.func() function
Thanks,
Mark
|
|
|
|
|
Actually, you are not using virtual functions for vFunc. You are simply re-defining the base class function. To use virtual functions for this, you would need to modify your code to:
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
virtual void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
virtual void vfunc() { cout << "Derived class vfunc.\n"; }
protected:
unsigned int numBullets;
};
int main() {
CBadGuy a;
CSoldier b;
a.vfunc();
b.vfunc();
return 0;
}
Even with this change you would get 'Base class vFunc' followed by 'Derived class vFunc'.
Often when using virtual functions it is desirable to not just "overide" a functions functionality, but to augment it. By doing this you can still use the base class implementation and only add what you want.
The following example demonstrates this.
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
virtual void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
virtual void vfunc() { cout << "Derived class vfunc.\n"; CBadGuy::vFunc();}
protected:
unsigned int numBullets;
};
int main() {
CSoldier b;
b.vfunc();
return 0;
}
This will result in 'Derived class vFunc' followed by 'Base class vFunc'. This can be very useful if you are creating your objects at run-time (ie new CSoldier) and passing them as pointers to CBadGuy); The following example demonstrated this.
class CBadGuy {
public:
CBadGuy();
virtual ~CBadGuy();
virtual void vfunc() { cout << "Base class vfunc.\n"; };
protected:
unsigned int speed;
unsigned int height;
char* description;
};
class CSoldier : public CBadGuy {
public:
CSoldier();
virtual ~CSoldier();
virtual void vfunc() { cout << "Derived class vfunc.\n"; }
protected:
unsigned int numBullets;
};
int main() {
CSoldier* pSolider = new CSoldier;
TestObject(pSoldier);
return 0;
}
void TestObject(CBadGuy* pTest)
{
pTest->vFunc();
}
In this scenario you would get the 'Dervice class vFunc' as output. This can be extremely powerful when you have a "class" of objects which share basic functionality and purpose but need to work in different ways.
|
|
|
|