locked
waveOutSetVolume doesn't works after "PowerState.POWER_STATE_ON" RRS feed

  • Question

  • //code PowerPolicyNotify((int) PPN_Message.PPN_UNATTENDEDMODE, 1); int iReturnResult = SetSystemPowerState(null, (int) PowerState.POWER_STATE_ON,(int)PowerRequirement.POWER_FORCE); and if i try to set the volume, it doesn't works... why? thanks
    Friday, April 16, 2010 1:32 PM

Answers

  • Hi Eymerich,

    I have a test like your code, it works fine in my local. I can change the volume, here is my code:

    public enum Volumes : int

            {

                OFF = 0,

                LOW = 858993459,

                NORMAL = 1717986918,

                MEDIUM = -1717986919,

                HIGH = -858993460,

                VERY_HIGH = -1

            }

     

            [DllImport("coredll.dll", SetLastError = true)]

            public static extern int waveOutSetVolume(IntPtr device, int volume);

     

            [DllImport("coredll.dll", SetLastError = true)]

            public static extern int waveOutGetVolume(IntPtr device, ref int volume);

     

            [DllImport("coredll.dll", CharSet=CharSet.Unicode)]

            private static extern bool PowerPolicyNotify(int dwMessage, int dwData);

     

     

            [DllImport("coredll.dll", SetLastError = true)]

     

            static extern int SetSystemPowerState(string psState, int StateFlags, int Options);

     

            public enum PPN_Message

     

            {

     

            PPN_REEVALUATESTATE = 0x0001,

     

            PPN_POWERCHANGE = 0x0002,

     

            PPN_SUSPENDKEYPRESSED = 0x0004,

     

            PPN_SUSPENDKEYRELEASED = 0x0005,

     

            PPN_APPBUTTONPRESSED = 0x0006,

     

            PPN_POWERBUTTONPRESSED = PPN_SUSPENDKEYPRESSED,

     

            PPN_UNATTENDEDMODE = 0x0003,

     

            PPN_OEMBASE = 0x10000

     

            }

     

            public enum PowerState

     

            {

     

            POWER_STATE_ON = 0x00010000,

     

            POWER_STATE_OFF = 0x00020000,

     

            POWER_STATE_CRITICAL = 0x00040000,

     

            POWER_STATE_BOOT = 0x00080000,

     

            POWER_STATE_IDLE = 0x00100000,

     

            POWER_STATE_SUSPEND = 0x00200000,

     

            POWER_STATE_UNATTENDED = 0x00400000,

     

            POWER_STATE_RESET = 0x00800000,

     

            POWER_STATE_USERIDLE = 0x01000000,

     

            POWER_STATE_PASSWORD = 0x10000000

     

            }

     

            public enum PowerRequirement

     

            {

     

            POWER_NAME = 0x00000001,

     

            POWER_FORCE = 0x00001000,

     

            POWER_DUMPDW = 0x00002000

     

            }

     

     

            private void frmWaveoutSetVolume_Load(object sender, EventArgs e)

            {

     

            }

     

            private void btnChangeHigh_Click(object sender, EventArgs e)

            {

                PowerPolicyNotify((int)PPN_Message.PPN_POWERBUTTONPRESSED, 0);//.PPN_UNATTENDEDMODE, 1);

     

                //SetSystemPowerState(null, (int)PowerState.POWER_STATE_UNATTENDED, (int)PowerRequirement.POWER_FORCE);

                int iReturnResult = SetSystemPowerState(null, (int)PowerState.POWER_STATE_ON, (int)PowerRequirement.POWER_NAME);

     

                int volume = (int)Volumes.HIGH;

                waveOutSetVolume(IntPtr.Zero, volume);

             }

     

            private void btnChangeLow_Click(object sender, EventArgs e)

            {

                PowerPolicyNotify((int)PPN_Message.PPN_POWERBUTTONPRESSED, 0);//.PPN_UNATTENDEDMODE, 1);

     

                //SetSystemPowerState(null, (int)PowerState.POWER_STATE_UNATTENDED, (int)PowerRequirement.POWER_FORCE);

                int iReturnResult = SetSystemPowerState(null, (int)PowerState.POWER_STATE_ON, (int)PowerRequirement.POWER_NAME);

     

                int volume = (int)Volumes.LOW;

                waveOutSetVolume(IntPtr.Zero, volume);

              

            }

    I test the code on emulator, not a real device, you can try it.

     

    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Thursday, April 22, 2010 2:48 AM

All replies

  • any help? thanks.
    Monday, April 19, 2010 10:07 AM
  • Hi Eymerich,

    As far as I know, volumn is nothing to do with power state. Can you show your code, we can have a test for it.

     

     

    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Tuesday, April 20, 2010 8:00 AM
  • public static void WakeUpPhone()
        {
    
          try
          {
            PowerPolicyNotify((int)PPN_Message.PPN_POWERBUTTONPRESSED, 0);//.PPN_UNATTENDEDMODE, 1);
    
            //SetSystemPowerState(null, (int)PowerState.POWER_STATE_UNATTENDED, (int)PowerRequirement.POWER_FORCE);
            int iReturnResult = SetSystemPowerState(null, (int)PowerState.POWER_STATE_ON, (int)PowerRequirement.POWER_NAME);
            Thread.Sleep(2000);
          }
          catch (Exception ex)
          {
          }
        }
    
    
    public static void SetVolumeMedium()
        {
                try
          {
            int res = waveOutSetVolume(IntPtr.Zero, (int)Volumes.MEDIUM);
            string r = res.ToString();
          }
          catch (Exception ex)
          {
          }
        }
    Tuesday, April 20, 2010 5:19 PM
  • Hi Eymerich,

    I have a test like your code, it works fine in my local. I can change the volume, here is my code:

    public enum Volumes : int

            {

                OFF = 0,

                LOW = 858993459,

                NORMAL = 1717986918,

                MEDIUM = -1717986919,

                HIGH = -858993460,

                VERY_HIGH = -1

            }

     

            [DllImport("coredll.dll", SetLastError = true)]

            public static extern int waveOutSetVolume(IntPtr device, int volume);

     

            [DllImport("coredll.dll", SetLastError = true)]

            public static extern int waveOutGetVolume(IntPtr device, ref int volume);

     

            [DllImport("coredll.dll", CharSet=CharSet.Unicode)]

            private static extern bool PowerPolicyNotify(int dwMessage, int dwData);

     

     

            [DllImport("coredll.dll", SetLastError = true)]

     

            static extern int SetSystemPowerState(string psState, int StateFlags, int Options);

     

            public enum PPN_Message

     

            {

     

            PPN_REEVALUATESTATE = 0x0001,

     

            PPN_POWERCHANGE = 0x0002,

     

            PPN_SUSPENDKEYPRESSED = 0x0004,

     

            PPN_SUSPENDKEYRELEASED = 0x0005,

     

            PPN_APPBUTTONPRESSED = 0x0006,

     

            PPN_POWERBUTTONPRESSED = PPN_SUSPENDKEYPRESSED,

     

            PPN_UNATTENDEDMODE = 0x0003,

     

            PPN_OEMBASE = 0x10000

     

            }

     

            public enum PowerState

     

            {

     

            POWER_STATE_ON = 0x00010000,

     

            POWER_STATE_OFF = 0x00020000,

     

            POWER_STATE_CRITICAL = 0x00040000,

     

            POWER_STATE_BOOT = 0x00080000,

     

            POWER_STATE_IDLE = 0x00100000,

     

            POWER_STATE_SUSPEND = 0x00200000,

     

            POWER_STATE_UNATTENDED = 0x00400000,

     

            POWER_STATE_RESET = 0x00800000,

     

            POWER_STATE_USERIDLE = 0x01000000,

     

            POWER_STATE_PASSWORD = 0x10000000

     

            }

     

            public enum PowerRequirement

     

            {

     

            POWER_NAME = 0x00000001,

     

            POWER_FORCE = 0x00001000,

     

            POWER_DUMPDW = 0x00002000

     

            }

     

     

            private void frmWaveoutSetVolume_Load(object sender, EventArgs e)

            {

     

            }

     

            private void btnChangeHigh_Click(object sender, EventArgs e)

            {

                PowerPolicyNotify((int)PPN_Message.PPN_POWERBUTTONPRESSED, 0);//.PPN_UNATTENDEDMODE, 1);

     

                //SetSystemPowerState(null, (int)PowerState.POWER_STATE_UNATTENDED, (int)PowerRequirement.POWER_FORCE);

                int iReturnResult = SetSystemPowerState(null, (int)PowerState.POWER_STATE_ON, (int)PowerRequirement.POWER_NAME);

     

                int volume = (int)Volumes.HIGH;

                waveOutSetVolume(IntPtr.Zero, volume);

             }

     

            private void btnChangeLow_Click(object sender, EventArgs e)

            {

                PowerPolicyNotify((int)PPN_Message.PPN_POWERBUTTONPRESSED, 0);//.PPN_UNATTENDEDMODE, 1);

     

                //SetSystemPowerState(null, (int)PowerState.POWER_STATE_UNATTENDED, (int)PowerRequirement.POWER_FORCE);

                int iReturnResult = SetSystemPowerState(null, (int)PowerState.POWER_STATE_ON, (int)PowerRequirement.POWER_NAME);

     

                int volume = (int)Volumes.LOW;

                waveOutSetVolume(IntPtr.Zero, volume);

              

            }

    I test the code on emulator, not a real device, you can try it.

     

    Best regards,
    Guang-Ming Bian - MSFT


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Thursday, April 22, 2010 2:48 AM