Something wrong with my function!?

This is a discussion on Something wrong with my function!? within the C++ Programming forums, part of the General Programming Boards category; I have created a function that is supposed to load a *.wav file usig DirectMusic. But the function doesnt pass ...

  1. #1
    Unregistered
    Guest

    Something wrong with my function!?

    I have created a function that is supposed to load a *.wav file usig DirectMusic. But the function doesnt pass WCHAR* szWAV corectly. szWAV is suposed to be the filename of my *.wav file...
    The program runs without errors but the sound doesn't work.

    Why doesn't the soundfile load? When I am not using the function it works fine...?!?!

    The code:

    void LoadSoundFile(IDirectMusicPerformance8 * PERFORMANCE, IDirectMusicSegment8 * SEGMENT, WCHAR* szWAV)
    {
    Loader->LoadObjectFromFile(CLSID_DirectMusicSegment,
    IID_IDirectMusicSegment8, szWAV, (void **) &SEGMENT);
    SEGMENT->SetParam(GUID_DirectMusicAllTypes, 0xFFFFFFFF,
    DMUS_SEG_ALLTRACKS, 0, NULL);
    SEGMENT->Download(PERFORMANCE);
    }

    How I'm using the function:

    //DirectSound stuff needed...
    IDirectMusicPerformance8 * Sound = NULL;
    IDirectMusicSegment8 * Gun = NULL;

    //Calling the funtion...
    LoadSoundFile(Gun, GunSound, L"Gun.wav");

    I didnt know where to post this question but I hope someone could help me out.

    Thanks for your help //Aram

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    post which lines cause errors and their respective messages, if your using direct-sound i think you have to include certain directx headers - make sure they are included and directx library and run time is available.

    Apart from that the only thing i can suggest is posting to Windows ro Game Board as it is DX specific
    Monday - what a way to spend a seventh of your life

  3. #3
    Unregistered
    Guest
    The program runs and everything its just that the file dosent load so that the buffer is still NULL. I can't figure it out why? I can even misspell the filename and the thing still runs without errors.

    By the way it shold be DirectMucis that I am using and not DirectSound...

  4. #4
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    There's a few things in your post that need to be cleared up.

    //Calling the funtion...
    LoadSoundFile(Gun, GunSound, L"Gun.wav");

    What's the L in there for, should be a typo in your post?



    IDirectMusicPerformance8 * Sound = NULL;

    Are you initializing the Sound/PERFORMANCE Var with a value other than NULL anywhere?


    According to the code you've posted it looks to me that you don't set the PERFORMANCE value to anything other than NULL. So when you code this...

    SEGMENT->Download(PERFORMANCE);

    ...it's pointing to NULL.

    OOOOOOOOOORRRRRRRRRRRRRRRRRRRRRRR

    I just saw this, why are you calling your Vars different names when calling the function...

    LoadSoundFile(Gun, GunSound, L"Gun.wav");

    you declared your vars to be "Gun" and "Sound", there's no GunSound.

    Plus, they are being called in a different order - shouldn't it be...

    LoadSoundFile(Sound, Gun,"Gun.wav");

    ???????????????????????

  5. #5
    Unregistered
    Guest

    Red face

    Uh oh!!!

    Damn I was really tired when I wrote the post but I'll try again.

    This is how the whole thing looks like it should be:

    //This is a funtion for initializing DirectMusicPerformance.
    //it is is the overall manager of music playback

    void InitDirectMusic(IDirectMusicPerformance8 * PERFORMANCE)
    {
    ::CoInitialize(NULL);

    ::CoCreateInstance(CLSID_DirectMusicPerformance, NULL,
    CLSCTX_INPROC, IID_IDirectMusicPerformance8,
    (void **)&PERFORMANCE);

    PERFORMANCE->InitAudio(NULL, NULL, NULL,
    DMUS_APATH_DYNAMIC_MONO,
    64, DMUS_AUDIOF_ALL, NULL);

    }

    //used to manage the enumeration and loading objects, it also cache them so that they are not loaded more then once
    IDirectMusicLoader8 * Loader;

    //Initiating the Loader
    void InitLoader()
    {
    ::CoInitialize(NULL);

    ::CoCreateInstance(CLSID_DirectMusicLoader, NULL,
    CLSCTX_INPROC, IID_IDirectMusicLoader8,
    (void **)&Loader);
    }

    //This is the part thats not working corectly.

    void LoadSoundFile(IDirectMusicPerformance8 * PERFORMANCE,
    IDirectMusicSegment8 * SEGMENT, WCHAR* szWAV)
    {
    Loader->LoadObjectFromFile(CLSID_DirectMusicSegment,
    IID_IDirectMusicSegment8, szWAV, (void **) &SEGMENT);
    SEGMENT->SetParam(GUID_DirectMusicAllTypes, 0xFFFFFFFF,
    DMUS_SEG_ALLTRACKS, 0, NULL);
    SEGMENT->Download(PERFORMANCE);
    }

    Now when I'm using all of this:

    IDirectMusicPerformance8 * Sound = NULL;
    IDirectMusicSegment8 * Gun = NULL;

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
    {
    //bla bla for creating the window and so on

    InitDirectMusic(Sound);
    InitLoader();

    //Now loading a soundfile. The L infront is needed or else I would call the ASCII string and not a UNICODE string.

    LoadSoundFile(Sound, Gun, L"Gun.wav");

    //here is the infinite loop...
    }

    I could load the file using the regular way like this:

    Loader->LoadObjectFromFile(CLSID_DirectMusicSegment,
    IID_IDirectMusicSegment8, L"Gun.wav", (void **) &Gun);
    Gun->SetParam(GUID_DirectMusicAllTypes, 0xFFFFFFFF,
    DMUS_SEG_ALLTRACKS, 0, NULL);
    Gun->Download(Sound);

    This is how LoadObjectFromFile is declared in the DirectMusic header if its to any help. I havent programed much so I'm not shure if understood it right.

    STDMETHOD(LoadObjectFromFile) (THIS_ REFGUID rguidClassID,
    REFIID iidInterfaceID,
    WCHAR *pwzFilePath,
    void ** ppObject) PURE;



    I hope I got it right this time...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 07:54 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21