Results 1 to 10 of 10

Thread: C++ and Phidgets

  1. #1
    Newbie
    Join Date
    May 2008
    Posts
    22

    C++ and Phidgets

    Well I bought ( http://www.phidgets.com/products.php?product_id=1052 ) in order to get a volume control.

    Problem is all I have is C++ and I'm not sure how to access the Windows Volume Control through C++.

    anyone know how I could achieve this?

  2. #2
    Constant Bitrate
    Join Date
    Jan 2006
    Location
    Montreal, QC, CA
    Posts
    196
    #include "stdafx.h"
    #include "Sound.h"

    //
    //
    //
    SoundDriver::SoundDriver(void)
    {
    m_nNumMixers = mixerGetNumDevs();
    m_hMixer = NULL;
    ::ZeroMemory(&m_mxcaps, sizeof(MIXERCAPS));

    m_strDstLineName.Empty();
    m_strMuteControlName.Empty();
    m_dwMuteControlID = 0;
    mixerOpen(&m_hMixer,0,reinterpret_cast<DWORD>(gDat a.GetHwnd()->GetSafeHwnd()),NULL,MIXER_OBJECTF_MIXER | CALLBACK_WINDOW);
    mixerGetDevCaps(reinterpret_cast<UINT>(m_hMixer),& m_mxcaps, sizeof(MIXERCAPS));

    MIXERLINE mxl;
    mxl.cbStruct = sizeof(MIXERLINE);
    mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
    mixerGetLineInfo(reinterpret_cast<HMIXEROBJ>(m_hMi xer), &mxl,MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE);

    MIXERCONTROL mxc;
    MIXERLINECONTROLS mxlc;
    mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
    mxlc.dwLineID = mxl.dwLineID;
    mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
    mxlc.cControls = 1;
    mxlc.cbmxctrl = sizeof(MIXERCONTROL);
    mxlc.pamxctrl = &mxc;
    mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(m _hMixer),&mxlc, MIXER_OBJECTF_HMIXER |MIXER_GETLINECONTROLSF_ONEBYTYPE);
    // store dwControlID
    m_strDstLineName = mxl.szName;
    m_strMuteControlName = mxc.szName;
    m_dwMuteControlID = mxc.dwControlID;

    mxlc.cbStruct = sizeof(MIXERLINECONTROLS);
    mxlc.dwLineID = mxl.dwLineID;
    mxlc.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
    mxlc.cControls = 1;
    mxlc.cbmxctrl = sizeof(MIXERCONTROL);
    mxlc.pamxctrl = &mxc;
    mixerGetLineControls(reinterpret_cast<HMIXEROBJ>(m _hMixer),&mxlc,MIXER_OBJECTF_HMIXER |MIXER_GETLINECONTROLSF_ONEBYTYPE);
    m_strVolumeControlName = mxc.szName;
    m_dwMinimum = mxc.Bounds.dwMinimum;
    m_dwMaximum = mxc.Bounds.dwMaximum;
    m_dwVolumeControlID = mxc.dwControlID;

    }

    //
    //
    //
    SoundDriver::~SoundDriver(void)
    {
    mixerClose(m_hMixer);
    }

    //
    //
    //
    bool SoundDriver::IsMute(void)
    {
    MIXERCONTROLDETAILS_BOOLEAN mxcdMute;
    MIXERCONTROLDETAILS mxcd;

    mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
    mxcd.dwControlID = m_dwMuteControlID;
    mxcd.cChannels = 1;
    mxcd.cMultipleItems = 0;
    mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
    mxcd.paDetails = &mxcdMute;
    mixerGetControlDetails(reinterpret_cast<HMIXEROBJ> (m_hMixer),&mxcd,MIXER_OBJECTF_HMIXER |MIXER_GETCONTROLDETAILSF_VALUE);
    return (bool)(!!mxcdMute.fValue);
    }

    //
    //
    //
    void SoundDriver::SetMute(bool mute)
    {
    MIXERCONTROLDETAILS_BOOLEAN mxcdMute = { (LONG)mute };
    MIXERCONTROLDETAILS mxcd;

    mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
    mxcd.dwControlID = m_dwMuteControlID;
    mxcd.cChannels = 1;
    mxcd.cMultipleItems = 0;
    mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_BOOLEAN);
    mxcd.paDetails = &mxcdMute;
    mixerSetControlDetails(reinterpret_cast<HMIXEROBJ> (m_hMixer),&mxcd, MIXER_OBJECTF_HMIXER | MIXER_SETCONTROLDETAILSF_VALUE);
    }

    //
    //
    //
    DWORD SoundDriver::GetMasterVolume(void)
    {
    MIXERCONTROLDETAILS_UNSIGNED mxcdVolume;
    MIXERCONTROLDETAILS mxcd;

    mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
    mxcd.dwControlID = m_dwVolumeControlID;
    mxcd.cChannels = 1;
    mxcd.cMultipleItems = 0;
    mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
    mxcd.paDetails = &mxcdVolume;
    mixerGetControlDetails(reinterpret_cast<HMIXEROBJ> (m_hMixer),&mxcd, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE);

    return (DWORD)((((float)mxcdVolume.dwValue)/655.35f)+0.5f);
    }

    //
    //
    //
    void SoundDriver::SetMasterVolume(DWORD dwVal)
    {
    MIXERCONTROLDETAILS_UNSIGNED mxcdVolume = { (DWORD)((float)dwVal*655.35f) };
    MIXERCONTROLDETAILS mxcd;

    mxcd.cbStruct = sizeof(MIXERCONTROLDETAILS);
    mxcd.dwControlID = m_dwVolumeControlID;
    mxcd.cChannels = 1;
    mxcd.cMultipleItems = 0;
    mxcd.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
    mxcd.paDetails = &mxcdVolume;
    mixerSetControlDetails(reinterpret_cast<HMIXEROBJ> (m_hMixer),&mxcd,MIXER_OBJECTF_HMIXER | MIXER_SETCONTROLDETAILSF_VALUE);
    }


    #ifndef SOUNDDRIVER_H
    #define SOUNDDRIVER_H

    class SoundDriver
    {
    public:
    SoundDriver(void);
    ~SoundDriver(void);
    bool IsMute(void);
    void SetMute(bool mute);
    DWORD GetMasterVolume(void);
    void SetMasterVolume(DWORD vol);
    private:
    UINT m_nNumMixers;
    HMIXER m_hMixer;
    MIXERCAPS m_mxcaps;
    CString m_strDstLineName, m_strMuteControlName,m_strVolumeControlName;
    DWORD m_dwMuteControlID;
    DWORD m_dwMinimum, m_dwMaximum;
    DWORD m_dwVolumeControlID;


    };

    #endif

  3. #3
    Newbie
    Join Date
    May 2008
    Posts
    22
    I'm missing an include or I'm including the wrong file but it can't find the "CString" class definition and giving me errors when i create one.

    which file am i missing to include?

  4. #4
    Variable Bitrate
    Join Date
    Apr 2006
    Location
    Dallas, Texas
    Posts
    264
    I haven't used C++ in ages but it should be in the stdafx.h. If not maybe the winafx.h?
    --------------------------
    Software Developed:
    DS-ATX Controller Interface
    Laptop Shutdown Controller

    Considered Projects:
    TPMS Interface
    Bluetooth Handsfree Interface (WIDCOMM/BROADCOMM)

  5. #5
    Variable Bitrate
    Join Date
    Apr 2006
    Location
    Dallas, Texas
    Posts
    264
    you can use the built in windows volume controls instead. It should be easier. If you were doing it in C# it would be

    [DllImport("winmm.dll")]
    public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);

    And then just call that method on turn of the dial. You should be able to do the same thing in C++.
    --------------------------
    Software Developed:
    DS-ATX Controller Interface
    Laptop Shutdown Controller

    Considered Projects:
    TPMS Interface
    Bluetooth Handsfree Interface (WIDCOMM/BROADCOMM)

  6. #6
    Newbie
    Join Date
    May 2008
    Posts
    22
    I've read that on another forum but i think what it said is that those commands were for the Windows Vista sound volume control.

  7. #7
    Constant Bitrate
    Join Date
    Jan 2006
    Location
    Montreal, QC, CA
    Posts
    196
    Quote Originally Posted by Ineffigy View Post
    I haven't used C++ in ages but it should be in the stdafx.h. If not maybe the winafx.h?
    AFXSTR.H

  8. #8
    Newbie
    Join Date
    May 2008
    Posts
    22
    afxstr.h is only used in MFC programs, so atlstr.h is what i needed to use. but thanks that's what fixed my error...

    BUT, now i have link errors:

    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetLineControlsW@12 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetLineInfoW@12 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetDevCapsW@12 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetNumDevs@0 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerClose@4 referenced in function "public: __thiscall SoundDriver::~SoundDriver(void)" (??1SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetControlDetailsW@12 referenced in function "public: bool __thiscall SoundDriver::IsMute(void)" (?IsMute@SoundDriver@@QAE_NXZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerSetControlDetails@12 referenced in function "public: void __thiscall SoundDriver::SetMute(bool)" (?SetMute@SoundDriver@@QAEX_N@Z)


    I always have a hard time with link errors and have no real clue how to fix them, am i missing a linked library?

  9. #9
    Constant Bitrate
    Join Date
    Jan 2006
    Location
    Montreal, QC, CA
    Posts
    196
    Quote Originally Posted by Ludercrs View Post
    afxstr.h is only used in MFC programs, so atlstr.h is what i needed to use. but thanks that's what fixed my error...

    BUT, now i have link errors:

    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetLineControlsW@12 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetLineInfoW@12 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetDevCapsW@12 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetNumDevs@0 referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerClose@4 referenced in function "public: __thiscall SoundDriver::~SoundDriver(void)" (??1SoundDriver@@QAE@XZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerGetControlDetailsW@12 referenced in function "public: bool __thiscall SoundDriver::IsMute(void)" (?IsMute@SoundDriver@@QAE_NXZ)
    1>Sound.obj : error LNK2019: unresolved external symbol __imp__mixerSetControlDetails@12 referenced in function "public: void __thiscall SoundDriver::SetMute(bool)" (?SetMute@SoundDriver@@QAEX_N@Z)


    I always have a hard time with link errors and have no real clue how to fix them, am i missing a linked library?

    Winmm.lib

  10. #10
    Newbie
    Join Date
    May 2008
    Posts
    22
    ah. thanks... now it's linking and the program works. I now have a volume Knob.

    Thanks everyone for your help.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •