Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Sorc.Polgara on December 30, 2004, 09:19 PM

Title: [C++] Header file organization.
Post by: Sorc.Polgara on December 30, 2004, 09:19 PM
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

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.
Title: Re: My Object Orientation, need critiicism/advice before I continue.
Post by: MyndFyre on December 30, 2004, 10:43 PM
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:


#pragma once

or

#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif

Title: Re: My Object Orientation, need critiicism/advice before I continue.
Post by: Kp on December 31, 2004, 11:35 AM
Don't use #pragma once.  Excerpt from GCC manual on why #pragma should not be used:

Quote2. 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.

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.
Title: Re: My Object Orientation, need critiicism/advice before I continue.
Post by: Sorc.Polgara on December 31, 2004, 11:42 AM
Quote from: MyndFyre on December 30, 2004, 10:43 PM
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:


#pragma once

or

#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif

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"?
Title: Re: My Object Orientation, need critiicism/advice before I continue.
Post by: MyndFyre on December 31, 2004, 01:19 PM
Quote from: Sorc.Polgara on December 31, 2004, 11:42 AM
Quote from: MyndFyre on December 30, 2004, 10:43 PM
Having header files really has nothing to do with object-oriented programming...

Also, make sure to use:


#pragma once

or

#ifndef PACKETBUFFER_H
#define PACKETBUFFER_H          // for example
...... (c code)

#endif

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"?

Kp has a good point about #pragma.  It's an option anyway, if you don't care about cross-platform compatibility.  :P
Title: Re: My Object Orientation, need critiicism/advice before I continue.
Post by: Kp on December 31, 2004, 02:12 PM
Quote from: MyndFyre on December 31, 2004, 01:19 PMKp has a good point about #pragma.  It's an option anyway, if you don't care about cross-platform compatibility.  :P

Or even cross-compiler compatibility.  MSVC isn't the only Win32 compiler, you know.