|
If you want to include everything.h in every cpp file, why not just include everything.h in stdafx.h (will speed up compiles). Ahh you say, "but then stdafx will get rebuilt everytime I make a change to a single header file". Yes, but then every file will be rebuilt any way.
Include only the header files you need in the cpp file, do not include extra unneed stuff, it will only slow you down. IMHO.
---
It may be that your sole purpose in life is simply to serve as a warning to others.
|
|
|
|
|
The trouble is, with such a large project, the include chain gets huge. For instance, file A.cpp requires A.h and B.h. But B.h requires C.h, D.h and E.h. And D.h requires, blah blah.
So A.cpp ends up including almost every header anyways.
I understand about the slowing down bit, but maybe it's worth a bit of a delay in compiling to have more clarity?
I dunno. But thanks for your opinion.
J
|
|
|
|
|
Clarity is nice, but if it's really a large project, the compile time will take forever. The best way to be really clear about the project about what headers belong in a class is to lay it out on paper.
Good programmers could excel in accounting if they wanted to!
|
|
|
|
|
I often put the includes in the headers themselves, so if A.h is dependent on B.h the #include "A.h" statement would appear in the beginning of B.h. When all the headers are protected by the
#if !defined(_some_unique_preprocessor_symbol)
#define(_some_unique_preprocessor_symbol)
class Myclass : public......
#endif
they'll only get compiled once anyway.
Of course, you can get into problems with finding the right include order and with circular includes, but in my experience this not too common.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
It seems to make my life much easier. But would the gods of style frown on me?
F*ck the gods of style. The problem is that your compile time will grow exponentially and when your project will grow further, the built time will be unacceptably slow and each small change will cause a rebuild.
You're entering the realm of physical (as opposed to logical) design here - I'd suggest reading 'Large Scale C++ Software Design' by John Lakos.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I'm aware of the compile-time issues... actually arranging it this was decreased compile time.
Perhaps a better way would be to have the required headers included in the header files themselves?
I've just ordered the book you suggested, but could you recommend a better tactic for me to consider while it ships?
Thanks for the input.
J
|
|
|
|
|
actually arranging it this was decreased compile time.
You're kidding, aren't you? Could you post your everything.h file?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Despite the fact that there's absolutely nothing of interest to any of our competitors in our stdafx.h file, posting it would likely be a breach of my contract and hence a Bad Thing(TM).
But no, I'm not kidding. Before I moved everything around, there were about a dozen includes in each file in the project (header and source). So it probably ended up including everything anyways... But one post recommend I put everything in the stdafx.h to take advantage of the MS precompiled header stuff, and holy crap, our build time jumped from about 4 minutes to about 40 seconds.
And of course now, when I make even minor changes to one of the headers, it has to recompile everything.
I understand now style-wise that it's not a good idea, and I'm really looking forward to reading that book you recommended (the reviews make it sound like it's the book I've been looking for for a few years). But could you post a suggested alternative?
It looks like I have 3 options:
1) Put everything in the stdafx.h file and suffer the long and finicky builds.
2) Have each source file include the files that it needs (in the order it needs them) and suffer from each source file having potentially dozens of includes that all have the be in the right order. Build times would be more reasonable.
3) Have each header file have its own includes for specific files that it needs. Have each source file include what it needs above and beyond what comes in through the includes in the included headers. This is clearer than 2 and faster than 1, but it's not as pretty as I would like.
Can it get prettier?
J
|
|
|
|
|
I see where the speedup comes from. However, your first post suggested that you had two files - stdafx.h and everything.h. I thought that you've just created one large non-precompiled header and included it everywhere. Well, this would be a disaster
The first thing to do is to check if you actually need all #includes in .h or even .cpp files. You can reduce interdependencies by using forward declarations whenever possible instead of #includes. In the end of the day you'll probably end with option (2).
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I had similar problem (I am still having it...).
I merge files, that I don't change any longer, or which are change very rarely. For example, I create one header file and one implementation file with 10 classes. Compiles faster, takes less time to operate on and load the project. Though it is hard to get used to it.
|
|
|
|
|
I am developing a small program to solve mazes so i need
to detect walls in the maze how can i do that ??
I need to read the color of an bitmap (MAP / MAZE)) in my dialog at a specific CPoint (mouse coordinates). Which Function should I use ????
Thanks
PS: I am an absolute beginner.
Nick Marchiori
marnicola90@hotmail.com
|
|
|
|
|
COLORREF CDC::GetPixel( POINT point ) const;
Nish
p.s. You can use a CPoint instead of a POINT
Sonork ID 100.9786 voidmain
|
|
|
|
|
GetPixel will work but it is very slow and should not be used in tight loops or real time situations. In those circumstances you should keep the bitmap in memory as a DIBSection ( this site has DIBSection classes in the bitmaps section, a DIBSection is like a CBitmap in that you can select it into a DC and draw it/draw onto it, but you also have access to the individual bits in a BYTE array ). This will mean converting from the mouse co-ordinates to the co-ordinates in the bitmap, but this is far less expensive than GetPixel.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Hello,
I trying to make a simple app to reboot windows 95 machines (And only windows 95).. I was reading some information from MSDN and they said because of the way the shell was written the only way to force/reboot windows 95 machines with out getting the "Do you want to save data" prompt.. is to kill the explorer.exe process then run the ExitWindowsEx(EWX_REBOOT,NULL).. they said this will force the system to reboot and all open document information will be lost.. This is exactly what I'm trying to do.. but I'm pretty new to process programing.. Whats the best way to get the explorer.exe process handle and kill it before I issue the ExitWindowsEx command?
Thanks!
Rob
|
|
|
|
|
see this link
http://support.microsoft.com/support/kb/articles/Q216/6/38.asp
Nish
Sonork ID 100.9786 voidmain
|
|
|
|
|
|
Hi all, I am back with yet another question (and its really bugging me!). I have successfully implemented some TWAIN support. That is, I can access the device drivers for the scanner etc. and select a device in the event of there being more than one. I can get the device session manager up too, from where I can get preview the picture etc. and I can actually get it to scan the area I want. However, when it comes to getting this image up onto the screen is where I`m having difficulty. I have looked at Rajiv's wrapper on this very web-site, and its really helped me get this far, however his code is very complicated (with v.few comments) when it comes to displaying the image on the screen, and completely differs from the way that I do it in my program. I create a DIBSection from the BITMAPINFO resource (which I can obtain in my program). However, when I try to create a DIBSECTION it returns a HBITMAP and there is merely a black rectangle(the same size and shape as the one I selected using the DSM after the preview). I have probably got the pointer to bits somewhere too amongst the void* I managed to obtain the BITMAPINFO from, but don`t know what I have to do to get at the right ones and get this blinking DIBSection of a scanned image going. Please help.
Cheers guys (for reading all that anyway)
Alan.
AEGC
|
|
|
|
|
how are you creating your DIBSection?
-c
POKE 808,234
|
|
|
|
|
Ruh roh...
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I have been creating my DIBSections using CreateDIBSection, as you will know this returns a HBITMAP, and any other pieces of info I may want ("the bits" etc.). However, I have got one step closer to finding a solution to this problem and I feel that your on the right lines Chris. I have now assertained a full BITMAPINFO structure (valid from the scanned image), and I even have a pointer to "the bits". However, my program relies on the HBITMAP structure that I need to create, if I use CreateDIBSection, the pointer I supply to the function is overridden and comes back with just black pixel values. Is there any way I can create the HBITMAP using the BITMAPINFO structure I have got and the pointer to "the bits"? I believe this is this problem is now solveable, but how?
Cheers Chris,
Alan.
|
|
|
|
|
can you show us a bit of your code (like where do you get your DCs from, any SelectObject stuff), etc?
=c
POKE 808,234
|
|
|
|
|
OK, I have actually managed to solve the problem, but I`d still appreciate it if you could tell me whether this code is efficient, and if not an alternative approach to solving the problem. The code below is generated from the OnAquisitionClick() function (which does all the TWAIN stuff) and passes the results to the AcquireImage() function, both of which are located in the MainFrame class of an MDI app. right here goes:
void CMainFrame::AcquireImage(HBITMAP hbitmap, TW_IMAGEINFO& info)
{
CBitmapDoc* pBitmapDoc = NewDocument();
CBitmapFrame* pBitmapWnd = (CBitmapFrame*)NewWindow(pBitmapDoc);
BYTE* lpVoid, *pBits;
LPBITMAPINFO pHead;
lpVoid = (BYTE*)GlobalLock(hbitmap);
pHead = (LPBITMAPINFO)lpVoid;
if(pHead->bmiHeader.biCompression != BI_RGB || pHead->bmiHeader.biBitCount != 24)
{
GlobalUnlock(lpVoid);
return;
}
pBits = (BYTE*)lpVoid + sizeof(BITMAPINFOHEADER);
HBITMAP newbitmap = CreateDIBitmap(pBitmapWnd->GetDC()->m_hDC, &pHead->bmiHeader, CBM_INIT, pBits, pHead, DIB_RGBCOLORS);
if(newbitmap)
{
pBitmapDoc->m_hAppliedTools.push_back(newbitmap);
pBitmapWnd->SetMinMaxWndSize(pHead->bmiHeader.biWidth, pHead->bmiHeader.biHeight);
pBitmapWnd->AddDYNAMenu(m_hFilters, m_hTools);
pBitmapDoc->SetTitle("Acquired");
m_hBitmapTemplate->InitialUpdateFrame(pBitmapWnd, pBitmapDoc, TRUE);
return;
}
else
AfxMessageBox("Cannot create new image acquisition graphic");
}
The one thing I do notice is that although I get all my information from hbitmap, if I try to use that Handle, the image is not drawn at all! I think, now that I`ve got this working, I may be able to figure out some better code to the job (I noticed some areas when I was just typing it out). One other thing, hbitmap may have been ascertained from the scanner as a HANDLE and not a HBITMAP (what I mean by that is that I could pass a HANDLE to one of the TWAIN acquire procedures and it still works). The handle is then passed to the procedure above. Hope you can enlighten/reassure me on my code.
Thanks again Chris,
Alan
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
Basically what I need to do is convert printing press CMYK colors to display RGB.
What I have been trying to do is this:
1) Get Profiles for display and press. In this case I'm using an RGB profile of CPQV1100.ICM (a Compaq supplied monitor profile) and a CMYK profile of CLC500M7.ICM which is a Canon profile for their color laser printer.
2) With the HPROFILES I then create an HTRANSFORM like this:
LOGCOLORSPACE lcs;
ZeroMemory(&lcs, sizeof(LOGCOLORSPACE));
lcs.lcsSignature = LCS_SIGNATURE;
lcs.lcsVersion = 0x400;
lcs.lcsSize = sizeof(LOGCOLORSPACE);
lcs.lcsCSType = LCS_WINDOWS_COLOR_SPACE;
lcs.lcsIntent = LCS_GM_IMAGES;
hTransform = CreateColorTransform(&lcs, hDestProfile, hTargetProfile, BEST_MODE);
3) I then fill a COLOR record like this
color.cmyk.cyan = 65535;
color.cmyk.magenta = 0;
color.cmyk.yellow = 0;
color.cmyk.black = 0;
4) Then I call:
TranslateColors(hTransform, &color, 1, COLOR_CMYK, &outcolor, COLOR_RGB);
5) The rgb colors in the outcolor structure come nowhere near the input colors.
I would greatly appreciate any help anyone can give in the use of ICM.
Thanks
Andy Brace
SW Development Engineer II
Qwest
A clear conscience is usually the sign of a bad memory.
|
|
|
|
|
Hi,
I'm using Boundschecker 6.2 to track down a tricky memory leakage problem. (It's not actually leaks, the memory is freed correctly - but too late).
The "Memory usage" window lists allocations by malloc/new/CoTaskMemAlloc & SysAllocString, I would need a similar list with the corresponding deletes. Any ideas?
TIA
Peter
|
|
|
|
|
i am trying to compile a test program with the following includes:
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
Do i need to download the SDK for this?
(i am new to VC++...)
|
|
|
|