Valhalla Legends Forums Archive | Battle.net Bot Development | [C++] Header file organization.

AuthorMessageTime
bethra
Ok, here I made a little list of the source files (.cpp) and the header files that each need to be included.  Some are ones that I made and others are ones that are built-in or w/e.

[quote]
Dependencies

packetbuffer.cpp
- windows.h
- iostream.h
- malloc.h

packetdebuffer.cpp
- windows.h
- iostream.h
- malloc.h

main.cpp
- winsock2.h
- windows.h
- stdlib.h
- iostream.h
- malloc.h
- SendBNCS.h
- SendBNLS.h
- RecvBNCS.h
- RecvBNLS.h
- packetdefs.h

RecvBNCS.cpp
- RecvBNCS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdebuffer.h
- packetdefs.h

RecvBNLS.cpp
- RecvBNLS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdebuffer.h
- packetdefs.h

SendBNCS.cpp
- SendBNCS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdefs.h

SendBNLS.cpp
- SendBNLS.h
- windows.h
- iostream.h
- malloc.h
- packetbuffer.h
- packetdefs.h
[/quote]

Many of the source share multiple header files in common.  An example would be the malloc.h, windows.h,  iostream.h,  packetdefs.h, and packetbuffer.h.

I get compiling errors when I try to include a header files in multiple source files.  Why exactly isn't it a good idea to make just a header file that includes header files that are share in common... it works when I compile it, yet some of you say it isn't something some of you would do...

And I have put the #ifndef code that mynd suggested.  I actually had it there before it was suggested because a C++ book I have put it there.
December 31, 2004, 3:19 AM
Myndfyr
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:

[code]
#pragma once
[/code]
or
[code]
#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif
[/code]
December 31, 2004, 4:43 AM
Kp
Don't use #pragma once.  Excerpt from GCC manual on why #pragma should not be used:

[quote]  2. There is no telling what the same #pragma might mean in another compiler.

These two reasons applied to almost any application that might have been proposed for #pragma. It was basically a mistake to use #pragma for anything. [/quote]

Also, I find it to be very disruptive to lay out my header files in the fashion you have described, as it really defeats the point of a dependency list if all the headers are included in every source file.  Then changing any header forces everything to be recompiled, even if the change had no relation to some of the afflicted files.  For instance, if you change the parameter list to your bot constructor, that doesn't affect the packetbuffer code - but your layout will force the packetbuffer to be rebuilt anyway.  Although it requires a bit more thought, I find it to be more convenient to have each source file include headers that it needs.  Of course, if packetbuffer.h makes no sense without windows.h included before it, there's a case for having packetbuffer.h include windows.h, since the compile is guaranteed to fail when windows.h isn't included.
December 31, 2004, 5:35 PM
bethra
[quote author=MyndFyre link=topic=10060.msg93923#msg93923 date=1104468233]
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:

[code]
#pragma once
[/code]
or
[code]
#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif
[/code]
[/quote]
ok.


Hmmmm while I'm here, I need to ask another question.

Back when I had made my VB Bot I had the login sequence all done.  However since then I've lost all my notes, pseudo code, programs that I did due to harddrive failure. That said, I have most of the sequence but the only thing that I can't remember is where I put the BNLS_CHOOSENLSREVISION (0x0D) in it.

I can't seem to place it.  Would this packet cause SID_AUTH_CHECK (0x51) to respond with an "0x101:  Invalid version"?
December 31, 2004, 5:42 PM
Myndfyr
[quote author=Sorc.Polgara link=topic=10060.msg93959#msg93959 date=1104514937]
[quote author=MyndFyre link=topic=10060.msg93923#msg93923 date=1104468233]
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:

[code]
#pragma once
[/code]
or
[code]
#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif
[/code]
[/quote]
ok.


Hmmmm while I'm here, I need to ask another question.

Back when I had made my VB Bot I had the login sequence all done.  However since then I've lost all my notes, pseudo code, programs that I did due to harddrive failure. That said, I have most of the sequence but the only thing that I can't remember is where I put the BNLS_CHOOSENLSREVISION (0x0D) in it.

I can't seem to place it.  Would this packet cause SID_AUTH_CHECK (0x51) to respond with an "0x101:  Invalid version"?
[/quote]

Kp has a good point about #pragma.  It's an option anyway, if you don't care about cross-platform compatibility.  :P
December 31, 2004, 7:19 PM
Kp
[quote author=MyndFyre link=topic=10060.msg93969#msg93969 date=1104520750]Kp has a good point about #pragma.  It's an option anyway, if you don't care about cross-platform compatibility.  :P[/quote]

Or even cross-compiler compatibility.  MSVC isn't the only Win32 compiler, you know.
December 31, 2004, 8:12 PM

Search