Controlling the volume while using the SndPlayAsync function on Windows Mobile 6 - c#

How on earth can you control the volume of the sound played using SndPlayAsync on Windows Mobile 6??
It seems like no one knows! The documentation doesn't mention anything regarding it...
So either there's no way, or it is kept top secret...
In addition, I am aware of the possibility of using the Windows Media Player, but I rather not, if possible.
Thanks for any help!
Aviv.

My suggestion is:
[DllImport("coredll.dll", SetLastError = true)]
protected static extern int waveOutSetVolume(IntPtr device, uint volume);
[DllImport("coredll.dll", SetLastError = true)]
internal static extern int waveOutGetVolume(IntPtr device, ref int volume);
And then you can call methods:
int before;
uint maxVol = uint.MaxValue;
waveOutGetVolume(IntPtr.Zero, ref before);
waveOutSetVolume(IntPtr.Zero, maxVol);
//Do some playing
waveOutSetVolume(IntPtr.Zero, before);
You can debug for other values. This will set it to highest.
Hope it helps?

You need to use the mixer... API functions to set the master volume. Here is a code sample:
http://www.csharp-home.com/index/tiki-read_article.php?articleId=134
To use this code in your Windows Mobile application, you need to change "winmm.dll" to "coredll.dll". Also, these methods may not be supported in Windows Mobile, but I'm pretty sure they are.

Related

Preventing Lock screen from Console Application [duplicate]

I am writing an application in C# that plays a movie. I need to figure out how to disable the screen saver and power options using C#.
I know the Windows SDK API has a function called SetThreadExecutionState() which can be used to do this, however, I do not know if there is a better way to do it. If not, how do I incorporate this function into C#?
Not sure if there is a better .NET solution but here is how you could use that API:
The required usings:
using System.Runtime.InteropServices;
The P/Invoke:
public const uint ES_CONTINUOUS = 0x80000000;
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
public const uint ES_DISPLAY_REQUIRED = 0x00000002;
[DllImport("kernel32.dll", SetLastError = true)]
public static extern uint SetThreadExecutionState([In] uint esFlags);
And then disable screensaver by:
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
Finnaly enable screensaver by reseting the execution state back to original value:
SetThreadExecutionState(ES_CONTINUOUS);
Note that I just picked one of the flags at random in my example. You'd need to combine the correct flags to get the specific behavior you desire. You will find the description of flags on MSDN.

How to hack Win32 API to get character limit to 32K

I want to use prefix \\\?\ as stated in this msdn BCL Team Blog, Long Paths in .NET, Part 2 of 3: Long Path Workarounds [Kim Hamilton]
Even after going through it again and again, I couldn't figure out how to actually use this feature, wondering if anyone can tell me simplest way to use it and how.
Note: I want to use it for creating a directory
You have to use Win32 functions and P/Invoke to achieve this. Use the Unicode version of the API.
Here's what you're looking for:
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool CreateDirectory(string lpPathName, IntPtr lpSecurityAttributes);
public static void CreateDir(string dirPath)
{
if (!CreateDirectory(#"\\?\" + dirPath, IntPtr.Zero))
{
throw new IOException("Could not create dir");
}
}
CreateDirectory method
More information about how naming works in Windows

Interface to change volume and play sound for HDA Audio device under Windows CE 6.0?

I develop C# .Net CF applications for a Win CE device, and am having problems getting the speaker volume change to affect actual volume when playing sound.
The interface I use is:
int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);
int PlaySound(string szSound, IntPtr hMod, int flags);
The code I use worked well with our old device which had the following setup:
AC'97 Audio codec, Windows CE 5, .Net CF 2.0.
However, on the new device the sound is played but I'm not able to change the volume. The setup is as follows:
HDA Audio codec, Windows CE 6, .Net CF 3.5.
I am uncertain whether this problem is within the Windows CE 6 OS image (e.g. missing/incorrect audio driver), or if I use the incorrect interface in my C# code.
Any help and ideas are most welcome!
Thanks,
Karl
Additional details:
Code:
public unsafe int SetVolume(int newVolumeInPercent)
{
UInt32 newVol = (UInt32)((double)(newVolumeInPercent * ushort.MaxValue) / 100.0);
newVol = newVol + (newVol << 16);
int resultSetVolume = waveOutSetVolume(IntPtr.Zero, newVol);
return (int)Math.Round((double)resultSetVolume * 100 / ushort.MaxValue);
}
public void playSound(string soundFile)
{
PlaySound(soundFile, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME));
}
[DllImport("CoreDll.dll")]
private extern static int waveOutSetVolume(IntPtr hMod, UInt32 dwVolume);
[DllImport("CoreDll.dll", EntryPoint = "PlaySound", SetLastError = true)]
private extern static int PlaySound(string szSound, IntPtr hMod, int flags);
private enum Flags
{
SND_ASYNC = 0x0001,
SND_FILENAME = 0x00020000,
}
As you see in the code, I use the argument percentage volume for both the left and right channel.
Using Windows CE Remote Process Viewer, I can see that the audio driver (i.e. "jwavehda.dll") is loaded. Also the "waveapi.dll" (generic Window wave api?) is loaded.
I do get sound when tapping the screen, and using the "PlaySound" function I am able to play a wave file. The only problem is that I cannot affect the volume.
Thanks!
I'd need to see your calling code (and your p/invoke declaration here are incomplete as well) to be sure. Are you aware that the waveOutSetVolume dwVolume is split into two words, the upper work being the left channel volume and the lower work being the right channel volume? The value you're sending in might be affecting the behavior (you didn't show that part of your code).
The fact that the code worked on one platform but fails on another indicates to me that it's likely an OS/Platform issue. Do you get audio for things like screen taps or other system events? Do you have an audio control panel applet? Did you look for an audio driver in the registry to make sure it both exists in the OS and is also loaded?

how to use ORIYA font in smart device development?

I am developing an application for WINDOWS CE5.0 based device. It requires ORIYA language(INDIAN REGIONAL LANGUAGE) to be used completely. As visual studio use ENGLISH as standard language, please tell me how to proceed? I tried to copy the font in WINDOWS CE device's WINDOWS/FONTS folder but as i restart the device that font file disappears. I developed the application in c# and changed labels text into oriyaa in Development system. It looks fine on the development system but as i deployed it into device, All label text appears in ENGLISH. I dont know whats happening? I also need to set the LABEL.TEXT property in ORIYA language. Is it possible? How to take user input in ORIYA? Please help..... Thanks...
Not very sure as what you meant by browser but for the Forms you can go about using PrivateFontCollection
you can load the font from a folder in your app and then use
AddFontFile or AddMemoryFont as per your need. So now the Client can see the controls in the font you set and its available to it irrespective of its installed or not
I have used the following approach with English-based fonts, but I am not sure if it will work on your case. The original source of this approach is a nice post from Chris Tacke (SO user #ctacke) with some modifications.
[DllImport("coredll.dll")]
private static extern int AddFontResource(string lpszFilename);
[DllImport("coredll.dll", SetLastError = true)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
static IntPtr HWND_BROADCAST = (IntPtr)0xFFFF;
const int WM_Fontchange = 0x001D;
private static void RegisterFont(string aFontPath, string aTargetFontPath)
{
IntPtr thir = (IntPtr)0;
IntPtr fourth = (IntPtr)0;
try
{
if (!System.IO.File.Exists(aTargetFontPath))
System.IO.File.Copy(aFontPath, aFontTargetPath);
}
catch { throw; }
int _Loaded = AddFontResource(aFontTargetPath);
if (_Loaded != 0)
SendMessage(HWND_BROADCAST, WM_Fontchange, thir, fourth);
}

Calling Native APIs from Managed Code

I am developing a Windows Mobile application using WM6 SDK. The application is a Managed code (using C#) & I would like to know the steps to be taken in order to call native functions.
Thanks for the help,
Abdel Olakara
http://www.pinvoke.net/
That should do it.
You need to first declare the native APIs as static extern using DLLImport and then use them like normal methods. Example:
[DllImport("user32.dll", ExactSpelling = true)]
internal static extern IntPtr SetTimer(IntPtr hWnd, IntPtr nIDEvent, int uElapse, IntPtr lpTimerFunc);

Categories