Jump to content
  • Advertisement
Sign in to follow this  

ComboBox playing up with DirectSoundEnumerate

This topic is 4118 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

Hi, i'm trying to enumerate any present sound devices using direct sound, so that if someone has more than 1 sound card they can choose which one they want, using a combobox which i fill in with each device. I'm using DirectSoundEnumerate which uses a callback to get the info on any sound devices, and then in the callback function i send messages to the combobox to add items. It's basically exactly the same as the enumerate sample which comes with the directx sdk. The values are placed in the combobox, however when i go to select one i get an exception InvalidArgument=Value of '1' is not valid for 'index'. or value of '0' is not valid if i choose the first one. It seems the indexes aren't updating for some reason. The code is as follows Heres there call to DirectSoundEnumerate, parameter 1 is the callback function, and two is the handle of my combobox for use later.
DirectSoundEnumerate(DSEnumProc2, (VOID*)this->comboBox1->Handle.ToPointer());

and heres the callback, lpContext is the handle of the combobox, so i can send messages to it.
			  LPCSTR lpszDesc,
			  LPCSTR lpszDrvName, 
			  LPVOID lpContext )
// Set aside static storage space for 20 audio drivers
    static GUID  AudioDriverGUIDs[20];
    static DWORD dwAudioDriverIndex = 0;

    GUID* pTemp  = NULL;

    if( pGUID )
        if( dwAudioDriverIndex >= 20 )
            return TRUE;

        pTemp = &AudioDriverGUIDs[dwAudioDriverIndex++];
        memcpy( pTemp, pGUID, sizeof(GUID) );

    HWND hSoundDeviceCombo = (HWND)lpContext;

    // Add the string to the combo box
    SendMessage( hSoundDeviceCombo, CB_ADDSTRING, 
                 0, (LPARAM) (LPCTSTR) lpszDesc );

    // Get the index of the string in the combo box
    INT nIndex = (INT)SendMessage( hSoundDeviceCombo, CB_FINDSTRING, 
                                   0, (LPARAM) (LPCTSTR) lpszDesc );

    // Set the item data to a pointer to the static guid stored in
    SendMessage( hSoundDeviceCombo, CB_SETITEMDATA, 
                 nIndex, (LPARAM) pTemp );

    return TRUE;

From setting afew breakpoints i know the following: -The handle for the combobox is being passed correctly, thus hSoundDeviceCombo is correct. -The messages are getting through, since the combobox gets filled in, and the return codes from the 3 SendMessage calls are OK. -The value of nIndex is correct i.e. it's being set to 0, 1 etc. -Heres the issue, i looked at the combobox in the debugger after the callbacks were done, and the Count property = 0 (ie. it thinks there is no items) and the Items field won't show the strings and has a big red exclamation mark next to it saying it can't retrieve the info, even though the correct strings are showing in the program. Is there something i've forgotten to do? This code is exactly the same as the sdk example and their one works ok.. Maybe because i'm sending it messages directly instead of using combobox->AddString(..) it's not updating properly? but i don't have direct access to my combobox from the callback. Using VSEE C++, DX9. Any ideas on this?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!