Announcement

Collapse
No announcement yet.

C++ and Phidgets

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    #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
    Enicar the RR Clone main thread : http://www.mp3car.com/vbulletin/soft...-rr-clone.html

    V0.09 is out : http://www.mp3car.com/vbulletin/soft...r-v0-09-a.html

    http://www.enitalp.net

    Comment


    • #3
      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?

      Comment


      • #4
        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)

        Comment


        • #5
          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)

          Comment


          • #6
            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.

            Comment


            • #7
              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
              Enicar the RR Clone main thread : http://www.mp3car.com/vbulletin/soft...-rr-clone.html

              V0.09 is out : http://www.mp3car.com/vbulletin/soft...r-v0-09-a.html

              http://www.enitalp.net

              Comment


              • #8
                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 [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::~SoundDriver(void)" (??1SoundDriver@@[email protected])
                1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: bool __thiscall SoundDriver::IsMute(void)" ([email protected]@@QAE_NXZ)
                1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: void __thiscall SoundDriver::SetMute(bool)" ([email protected]@@[email protected])


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

                Comment


                • #9
                  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 [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                  1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                  1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                  1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::SoundDriver(void)" (??0SoundDriver@@[email protected])
                  1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: __thiscall SoundDriver::~SoundDriver(void)" (??1SoundDriver@@[email protected])
                  1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: bool __thiscall SoundDriver::IsMute(void)" ([email protected]@@QAE_NXZ)
                  1>Sound.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "public: void __thiscall SoundDriver::SetMute(bool)" ([email protected]@@[email protected])


                  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
                  Enicar the RR Clone main thread : http://www.mp3car.com/vbulletin/soft...-rr-clone.html

                  V0.09 is out : http://www.mp3car.com/vbulletin/soft...r-v0-09-a.html

                  http://www.enitalp.net

                  Comment


                  • #10
                    ah. thanks... now it's linking and the program works. I now have a volume Knob.

                    Thanks everyone for your help.

                    Comment

                    Working...
                    X