Can't find P/Invoke winmm.dll

K

krupa.p

Hi All,

I am trying to call the waveOutGetVolume() function in winmm.dll from
my VS 2005 C# project using P/Invoke. I copied winmm.dll from
Windows\system32 directory into the root directory of my project. When
I run the solution, I get an error: Can't find PInvoke DLL 'winmm.dll'.

I have my code below. Could someone please help?

<code>

public partial class Form1 : Form
{
private class volAPI
{
[DllImport("winmm.dll" , EntryPoint = "waveOutGetVolume",
SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int waveOutGetVolume(IntPtr hwo, out
uint dwVolume);

[DllImport("winmm.dll", EntryPoint = "waveOutSetVolume",
SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int waveOutSetVolume(IntPtr hwo, uint
dwVolume);
}

public Form1()
{
InitializeComponent();
uint CurrVol = 0;
// At this point, CurrVol gets assigned the volume
volAPI.waveOutGetVolume(IntPtr.Zero, out CurrVol);
// Calculate the volume
ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
MessageBox.Show("Vol: " + CalcVol.ToString());
}
}

</code>
Regards,
Krupa
 
M

Mattias Sjögren

I copied winmm.dll from
Windows\system32 directory into the root directory of my project.

Why? It should be found in the System32 directory.


Mattias
 
W

Willy Denoyette [MVP]

As Mattias said you should not copy te dll from system32 to your application
directory.
What is the "exact" message you get when you call this function?
Note also that this function will fail with a null Handle for hwo! You have
to open a waveout device before you can call waveOutGetVolume or most other
Waveform function.

Willy.

| Hi All,
|
| I am trying to call the waveOutGetVolume() function in winmm.dll from
| my VS 2005 C# project using P/Invoke. I copied winmm.dll from
| Windows\system32 directory into the root directory of my project. When
| I run the solution, I get an error: Can't find PInvoke DLL 'winmm.dll'.
|
| I have my code below. Could someone please help?
|
| <code>
|
| public partial class Form1 : Form
| {
| private class volAPI
| {
| [DllImport("winmm.dll" , EntryPoint = "waveOutGetVolume",
| SetLastError = true, CharSet = CharSet.Unicode)]
| public static extern int waveOutGetVolume(IntPtr hwo, out
| uint dwVolume);
|
| [DllImport("winmm.dll", EntryPoint = "waveOutSetVolume",
| SetLastError = true, CharSet = CharSet.Unicode)]
| public static extern int waveOutSetVolume(IntPtr hwo, uint
| dwVolume);
| }
|
| public Form1()
| {
| InitializeComponent();
| uint CurrVol = 0;
| // At this point, CurrVol gets assigned the volume
| volAPI.waveOutGetVolume(IntPtr.Zero, out CurrVol);
| // Calculate the volume
| ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
| MessageBox.Show("Vol: " + CalcVol.ToString());
| }
| }
|
| </code>
| Regards,
| Krupa
|
 
K

krupa.p

Thanks Willy and Mattias for your replies.

I am debugging my application on a Win CE device. I get a
MissingMethodException on the device when I call this function. The
error reads:

Error
VOL_TEST.EXE
MissingMethodException
Can't find PInvoke DLL 'winmm.dll'

Any ideas?

-Krupa
 
L

Lucian Wischik

Error
VOL_TEST.EXE
MissingMethodException
Can't find PInvoke DLL 'winmm.dll'
Any ideas?

winmm.dll is kind of like a device-driver for windows multimedia
functions. It certainly won't work to copy the DLL from "real" windows
to CE!


You need to go back and read the CE documentation for the functions
you're trying to call. In this case, read the CE documentation for
waveOutGetVolume. It says: "Link library coredll.lib".

http://msdn.microsoft.com/library/d...ewave/html/_wcesdk_win32_waveoutgetvolume.asp

So I suggest you look for a DLL with a similar name on your CE device,
and PInvoke it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top