|
The compiler will ignore the included file above stdafx.h...
You should get a warning as well, something like
warning C4627: '#include <foo.h>': skipped when looking for precompiled header use
To do something like that negates the usefulness of a precompiled header anyway....why would you do it?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark,
I am reading MSDN definition for the file name parameter from,
http://msdn2.microsoft.com/zh-cn/library/7zc28563(en-us).aspx
[^]
here is the meaning for the file parameter from MSDN,
--------------------
Specifies a header (.h) file. When this argument is used, the compiler
compiles all code up to and including the .h file.
--------------------
For exmaple, we have a file like this,
include "stdafx.h"
1. Does it mean when we compile the file, only stdafx.h and section 2 are compiled?
2. Or does it mean when compiler do the precompile, section 1 and stdafx.h will be pre-compiled into some .pch file?
regards,
George
|
|
|
|
|
Hi,
AFAIK, it is a rule that every cpp file in program should include "stdafx.h" and also it should be in the first line before including any other header.
Best Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
|
Hi,
I am not sure, I think as Mark said, whatever in the "section1" will be ignored and remaining will be compiled.
You can check it by using some mathmatics functions in your cpp file and include the "math.h" before "stdafx.x", you may get error.
Best Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
Thanks Suman,
For the pre-compile phase to generate pre-compiled headers (.pch), is only stdafx.h used to generate the client.pch or both section 1 and stdafx.h are used to generate the client.pch?
(you can check my original post for more details about context)
regards,
George
|
|
|
|
|
There's a third compiler option you need to work with here
/Yc Create precompiled header
/Yu Use precompiled header
If you look closely at the settings for a wizard-generated Visual C++ project,
ONE source file uses the /Yc option to create the precompiled header....this is typically
stdafx.cpp. All the other source files use the /Yu compiler option, to use the precompiled
header.
The "Create/Use PCH through file" option has two uses -
1) when used with /Yc, it specifies the file to stop precompilation on (at the end of)
2) when used with /Yu, it specifies the file to replace with the precompiled header
This has the following effects if "stdafx.h" is the "Create/Use PCH through file" setting:
1) For the file compiled with the /Yc option, everything included before and through the stdafx.h file
is compiled into a precompiled header file.
2) For any files compiled with the /Yu option, everything included before and through the stdafx.h file
is ignored and replaced with the precompiled header file.
Hopefully I explained that OK.
More info here: /Yu (Use Precompiled Header File)[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark!
I read through the wonderful reply and information referred by you. I think in my case, I need to creat two pre-compiled files since for each source file, the pre-compiled information are different, right?
regards,
George
|
|
|
|
|
George_George wrote: I think in my case, I need to creat two pre-compiled files since for each source file, the pre-compiled information are different, right?
First, I'm not sure how well that works, but you could easily try it.
But a precompiled header is really meant for common definitions - e.g. CRT headers, Windows SDK headers, app-common classes, etc.
For anything that varies between source files, those should be included separately, and in fact, must be.
The precompiled header is available just for efficiency, so the compiler doesn't have to waste extra time compiling the same
exact items for every source file.
I personally have never encountered a case where I needed to have more than one PCH file like you're showing, with differing
include files above the precompiled header.
The standard PCH usage...
...#includes and definitions used by all modules go in here
#include "stdafx.h"
#include "stdafx.h"
#include <math.h>
#include <vfw.h>
...
#include "stdafx.h"
#include <vector>
#include <string>
... ...always works fine for me.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your advice, Mark!
I think I need to merge them into one pch file.
regards,
George
|
|
|
|
|
Hi I would like to Know the steps reqd to connect from VC++9 to oracle?
Cheers
|
|
|
|
|
|
Hi all,
I m working on VC++2005, and my application is SDI type.
when i run my application in MENUBAR the option of Print and print preview are disabled.
any one can tell me how can enable them.
Thanks in advance
|
|
|
|
|
Hi,
Is this discussion helpful: print handler[^]?
Best Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
Hi all,
i have an problem in load icon for sub-dialog box.
i want to show main application icon on subdialog box or internal dialog box of application.
i m using this.
HICON m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
where IDR_MAINFRAME is icon of main application.but it not works.
anyone can help me.
thanks in advance
|
|
|
|
|
Hi,
Are you calling SetIcon() to set the loaded icon or not?
Best Regards,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
thanks. now my problem is resolved
|
|
|
|
|
|
|
Where are you trying to change it? In the VS6 resource editor for example you right-click on the stringtable in Resource View -> Properties -> Language.
|
|
|
|
|
Today I wrote some code for my program. Unfotunately, it didn't work, and the reason was RegQueryValueEx failed Please check my code and help me to determine why it's fail.
DWORD dwType = REG_DWORD;
DWORD dwLength = sizeof(DWORD);
HKEY hkey;
long lres = RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\DeltaX\\TicTacToe"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hkey);
if(lres!=ERROR_SUCCESS)
{
lres = RegCreateKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\DeltaX\\TicTacToe"),0,NULL,
REG_OPTION_VOLATILE,
KEY_SET_VALUE|KEY_QUERY_VALUE,
NULL,
&hkey,
NULL);
}
lres = RegQueryValueEx(hkey,TEXT("DifficultLevel"),NULL,&dwType,(PBYTE)&dwMode,&dwLength);
if ((lres!=ERROR_SUCCESS))
{
dwMode = 1;
RegSetValueEx(hkey,TEXT("DifficultLevel"),NULL,REG_DWORD,(LPBYTE)&dwMode,sizeof(DWORD));
}
RegCloseKey(hkey);
everything seems to be fine, but nothing's done. dwMode var gets 0 value, and I don't know why
I checked the registry, and the value of dwMode is OK.
Please tell me why
Thanks in advance
|
|
|
|
|
The code you provided never sets dwMode to 1
Maybe it should be:
if ((lres==ERROR_SUCCESS))
{
dwMode = 1;
RegSetValueEx(hkey,TEXT("DifficultLevel"),NULL,REG_DWORD,(LPBYTE)&dwMode,sizeof(DWORD));
}
|
|
|
|
|
Thank you, but you don't understand my code. In case that RegQueryValueEx fails (cause of something such as the value doesn't exit, etc), my program will re-create that value for later run.
Anyway, I changed my code and now it works well.
lres = RegQueryValueEx(hkey,TEXT("BoardSize"),0,&dwType,(PBYTE)&dwSize,&dwLength);
Thank you all!
|
|
|
|
|
Vimvq1987 wrote: ...RegQueryValueEx failed . Please check my code and help me to determine why it's fail.
I see no call to GetLastError() . Why?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello everyone,
What I am confused is about,
http://www.gotw.ca/gotw/059.htm
--------------------
Indeed, often the best way to implement the Pimpl idiom is exactly as shown in Example 4 above, by using a pointer (in order to take advantage of nonthrowing operations) while still wrapping the dynamic resource safely in an auto_ptr manager object. Just remember that now your object must provide its own copy construction and assignment with the right semantics for the auto_ptr member, or disable them if copy construction and assignment don't make sense for the class.
--------------------
1. What means "the right semantics for the auto_ptr member"?
2. "disable" means for the class, copy construction and assignment are not needed? Curious. Never thought of a class which does not need that two basic functions.
thanks in advance,
George
|
|
|
|
|