Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Zyroth

Ok... I'm stumped

This topic is 5744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I''ve included my own header file Sound.h in two cpp files. In the header file I''ve defined SOUND_H and when I go to include them I use #ifndef SOUND_H #include "Sound.h" #endif But it''s not working, its giving me build errors because thing are of course alreasy defined. I already checked the spelling and that I defined them properly. What am I doing wrong here?

Share this post


Link to post
Share on other sites
Advertisement

Put this in sound.h at the top

#if !defined ( SOUND_H )
#define SOUND_H

....include all of sound.h here

#endif

Share this post


Link to post
Share on other sites
Hi, in .cpp file simply include de .h file:

#include "Sound.h"

and in the Sound.h do this:

#ifndef SOUND_H
#define SOUND_H

// File code...

#endif

That''s it. It should work correctly.
Hope this helps.

Bye

Share this post


Link to post
Share on other sites
Inside sound.h itself put:

#ifndef SOUND_H
#define SOUND_H

blah blah blah

#endif

..........

Then in your source files, just include "sound.h"

See if that helps.

EDIT: Whoa, lots of replies there!

[edited by - Waverider on October 2, 2002 12:34:10 PM]

Share this post


Link to post
Share on other sites
---CUT---
You can also use the #pragma once directive, which has the same effect.

[edited by - Prototype on October 2, 2002 12:41:37 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
While we''re on the subject. Does anybody know if #pragma once is MSVC specific?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok, I just tried #pragma once with gcc and got a warning saying it''s obsolete... So... yeah...

Share this post


Link to post
Share on other sites
I tried putting my code in the #ifndef but it still doesn''t work.

These are the errors that I''m getting:

Linking...
Sound.obj : error LNK2005: "struct _DSBUFFERDESC dsbd" (?dsbd@@3U_DSBUFFERDESC@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct tWAVEFORMATEX pcmwf" (?pcmwf@@3UtWAVEFORMATEX@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct pcm_sound_typ * sound_fx" (?sound_fx@@3PAUpcm_sound_typ@@A) already defined in main.obj
Sound.obj : error LNK2005: "struct IDirectSound * lpds" (?lpds@@3PAUIDirectSound@@A) already defined in main.obj
Debug/builder.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

builder.exe - 5 error(s), 0 warning(s)

Any Ideas...

Share this post


Link to post
Share on other sites
Did you put the #define in after the ifndef?

Think about what you are trying to do here - if it isn''t defined, then include the file and define it, if its already defined, then ignore everything.

Share this post


Link to post
Share on other sites
yeah my code pretty much goes:

#ifndef WINDOWS_H
#include <windows.h>
#endif

#ifndef MMSYSTEM_H
#include <mmsystem.h>
#endif

#ifndef DSOUND_H
#include <dsound.h>
#endif

#ifndef SOUND_H
#define SOUND_H

#define DSVOLUME_TO_DB( volume ) ( ( DWORD )( -30*( 100 - volume ) ) )
#define MAX_SOUNDS 256

#define DSBCAPS_CTRLDEFAULT DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLFREQUENCY

// digital sound object state defines
#define SOUND_NULL 0 // " "
#define SOUND_LOADED 1
#define SOUND_PLAYING 2
#define SOUND_STOPPED 3

struct pcm_sound_typ
{
LPDIRECTSOUNDBUFFER dsbuffer;
int state;
int rate;
int size;
int id;
};

pcm_sound_typ sound_fx[ MAX_SOUNDS ];

LPDIRECTSOUND lpds;
DSBUFFERDESC dsbd;
WAVEFORMATEX pcmwf;

bool InitDS( HWND hwnd );
bool PlayDS( bool loopSound, int id );
bool StopDS( int id );
bool SetVolumeDS( int vol, int id );
bool SetFrequencyDS( int freq, int id );
bool SetPanDS( int pan, int id );
bool DeInitDS();
int Load_WAV( char* filename, int CONTROL_FLAGS = DSBCAPS_CTRLDEFAULT );

#endif

[edited by - zyroth on October 2, 2002 4:45:21 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!