|
Sarvan AL wrote: I am getting the error "fatal error: unexpected end of file while looking for precompiled header directive". But If I add "#include "stdafx.h" in Person.cpp, I get another error "CPerson: class type redefinition"
To solve the first error you have to #include "stdafx.h" . To solve the second error place a #pragma once at the top of every one of your .h header files. What is happening now is that the compiler is including person.h multiple times so it is finding multiple definitions of class CPerson .
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
1. I have one similar problem please help me also. I tried to use a global variable in every c++ file with the same name that is szRegPath (a CString). But I got some error and I had to use either different variable names in all the files (if global) or i had to put those inside functions. How can I resolve this?
2. I want to have one int variable which is global to all the c++ files and that should maintain its value state. If one file modifies the value to 7, then when it is called by another file, it should have its value as 7.
Please help me
Aljechin Alexander
|
|
|
|
|
Declare the variable as external using "extern" in all the files.
(like ... extern CString szRegPath). Hope this helps.
Pls let us know your status.
|
|
|
|
|
I will try this and definitely write back
Thank you so much
Aljechin Alexander
|
|
|
|
|
extern CString strGlobal = "Initialization Value";
extern CString strGlobal;
AfxMessageBox(strGlobal);
This gives me an error telling one unresolved external symbol
Regards,
Aljechin Alexander
|
|
|
|
|
You got it backwards.
Put this in exactly ONE source file, your definition of the global variable:
extern CString strGlobal = "Initialization Value";
Put this in the header file, included by all source files that need access to the variable:
extern CString strGlobal;
That should work.
Marriage slows down your coding, a baby slows it down even more!
|
|
|
|
|
Blake Miller wrote: You got it backwards.
I am still not getting it
Please show me in stdafx.h what i should put, in MySample.cpp and MySample.h what I should put? There are about 10 files, say MySample2.h, MySample2.cpp, etc.. in those what I should put? Show me the code please. I have never done this before. Sorry if I am troubling too much.
Regards,
Aljechin Alexander
-- modified at 23:55 Thursday 12th January, 2006
|
|
|
|
|
MySample.H
extern CString strGlobal;
MySample.Cpp
#include "MySample.H"
// declare variable in ONLY one source file
CString strGlobal = "Initialization Value";
MyOtherSample.Cpp
#include "MySample.H"
|
|
|
|
|
Yes, I got it. As ....PJ Arends... said, I put #pragma once in all the .h files and #include "stdafx.h" as the first statement of all the .cpp files. Also I removed #include "PersonDlg.h" statement from the Person.h file. Now it works fine. But I have not changed the compiler option to "Not using percompiled header files..". Just I left it, as it is.
Thanks once again
Sarvan AL
|
|
|
|
|
In the project that i am developing i need to communicate between two and more exe. how can i carry this out?
|
|
|
|
|
There are many ways, it really depends on what your needs are. You can used the clipboard, memory mapped files, pipes, mailslots, DDE, WM_COPYDATA, or windows sockets, etc.
See the articles listed at http://www.codeproject.com/threads/#Inter%2DProcess+Communication[^]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
If I create butons and statics in my normal window they do not match those in my dialogue boxes (the font is different).
I can change the font in main window but I don't know what settings to use. Arial doesn't seem right, anyone know what they should be?
Thanks,
Ali
|
|
|
|
|
|
Thanks for the advice, I will try it out.
Ali
|
|
|
|
|
Hi All
How to pass a function name as argument of another function
eg
void Test()
{
}
main()
{
Do(Test)
}
by
KK
|
|
|
|
|
|
void Test() { printf("test\n"); }<br />
<br />
void Do(void fn()){ fn(); }<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
Do(Test);<br />
return 0;<br />
}
|
|
|
|
|
You don't pass a function name as argument as another function but rather a pointer to a function:
First, you have to describe what is the 'type' of the function, for example:
typedef void (MyFunc*) (int,int);
This is a typedef that says that MyFunc is a type definition of a function returning nothing (the first void before (MyFunc*) ) and that takes two integer arguments (the argument list is specified after (MyFunc*) ).
Then, you can use MyFunc as a standard argument to a function:
void Do(MyFunc MyFuncThatWillBePassed)<br />
{<br />
}
This explain that the Do function will receive a pointer to a function of the type MyFunc as argument.
Inside your Do function, when you want to call your function, simply do that:
void Do(MyFunc MyFuncThatWillBePassed)<br />
{<br />
int a=0,b=0;<br />
MyFuncThatWillBePassed(a,b);<br />
}
Warning: you have to respect of course the type of the function and so you NEED to pass two integers (in our case) to your function otherwise you will have compile errors.
Hope this helps
|
|
|
|
|
it should be
typedef void (*MyFunc) (int,int);
|
|
|
|
|
Ooops... Sorry typo mistake
|
|
|
|
|
Hi
Thanx for all answers
by
KK
|
|
|
|
|
My Google skills are failing me this evening; does anyone have any examples or pointers for creating Sticky windows? Basically what I want is to create dialogs that stick to each other like Win Amp’s play list editor and its main dialog.
Any help is appreciated.
ZeePain! wrote: This seems like one of those programs that started small, grew incrementally, building internal pressure, and finally barfed all over its source code sneakers. Or something.
thedailywtf.com[^]
|
|
|
|
|
Tried a search on CP with "docking windows" ?
~RaGE();
|
|
|
|
|
Rage wrote: "docking windows"
Funny about a minute ago it dawned on me to change my search params. Low and behold there is all kinds of info. Gee
Thank you for the reply.
ZeePain! wrote: This seems like one of those programs that started small, grew incrementally, building internal pressure, and finally barfed all over its source code sneakers. Or something.
thedailywtf.com[^]
|
|
|
|
|
I have a .DBF file. Is it possible to do some database operation on this file using ODBC on some machine where SQL Server is not installed? If so can you show me a small code sample? (The application that i use is written in Visual C++ 6.0)
Thanks
Aljechin Alexander
|
|
|
|