[Windows Mobile Software Development] vbilenko:
Dear сolleagues and development guru!

I have some stopper in Power Management. I hope somebody will help me to understand.

Technologies: C#, .NET 3.5

The main point of application:

Make beep periodically.

Main problem is:

When PocketPC in active mode application running correct, but when PocketPC went to sleep mode it does not make a beep. As I understood speaker is turned off in sleep mode (like all other devices in PocketPC).

Question:

How can I turn on speaker in sleep mode?

Simply what I need is turn on speaker, make beep and back speaker to previous mode without wake up all device.

I tried code like this:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Media;
using System.Threading;
using System.Runtime.InteropServices;

namespace TestProject
{
static class Program
{

public const int POWER_NAME = 0x00000001;

public enum DevicePowerState : int
{
Unspecified = -1,
D0 = 0,
D1,
D2,
D3,
D4,
}

[DllImport("coredll.dll", SetLastError = true)]
public static extern int SetDevicePower(
string pvDevice,
int dwDeviceFlags,
DevicePowerState DeviceState
);

[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr SetPowerRequirement(
string device,
DevicePowerState state,
uint deviceFlags,
IntPtr systemState,
ulong stateFlags
);

[DllImport("coredll.dll", SetLastError = true)]
public static extern int ReleasePowerRequirement(IntPtr handle);

[MTAThread]
static void Main()
{

MessageBox.Show("Application is running...", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);

string deviceName = "WAV1:"; // speaker

for (; ; )
{
// set D0 power value
IntPtr handle = SetPowerRequirement(deviceName, DevicePowerState.D0, 1, IntPtr.Zero, 0);

// make a beep
SystemSounds.Beep.Play();

// set default power value
ReleasePowerRequirement(handle);

Thread.Sleep(10000);
}
}
}
}

And like this:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Media;
using System.Threading;
using System.Runtime.InteropServices;

namespace TestProject
{
static class Program
{

public const int POWER_NAME = 0x00000001;

public enum DevicePowerState : int
{
Unspecified = -1,
D0 = 0,
D1,
D2,
D3,
D4,
}

[DllImport("coredll.dll", SetLastError = true)]
public static extern int SetDevicePower(
string pvDevice,
int dwDeviceFlags,
DevicePowerState DeviceState
);

[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr SetPowerRequirement(
string device,
DevicePowerState state,
uint deviceFlags,
IntPtr systemState,
ulong stateFlags
);

[DllImport("coredll.dll", SetLastError = true)]
public static extern int ReleasePowerRequirement(IntPtr handle);

[MTAThread]
static void Main()
{

MessageBox.Show("Application is running...", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);

string deviceName = "WAV1:"; // speaker

int resDevicePowerOn = SetDevicePower(deviceName, POWER_NAME, DevicePowerState.D0);

for (; ; )
{
// make a beep
SystemSounds.Beep.Play();

Thread.Sleep(10000);
}
}
}
}

But any of these codes does not work - there are no beep in sleep mode.