0
votes

Im using VS2005 and im making a project in vb.net, I was trying to add winmm.dll file but i got this error.

A reference to 'C:\Documents and Settings\rhyatco\My Documents\winmm.dll' could not be added. This is not a valid assembly or COM component. Only assemlies with extension 'dll' and COM components can be refenced. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

I've already downloaded 2 winmm.dll but it doesnt really work.

4
Please tell us what you want to do, not how you tried to do what you want. Then we can give you intelligent answers and maybe other solutions that you havent thought about. - Stefan

4 Answers

5
votes

Winmm.dll contains win32 api functions, not com components or .net types.

To use the function in the dll from VB you need to use the "declare statement".

You can find information on the syntax for "declare statements" here.

1
votes

Probably because winmm.dll isn't a COM DLL nor a .Net assembly.

0
votes

If you want to use winmm.dll for example to play a sound (example copied from pinvoke.net) Goto http://www.pinvoke.net/ to get examples and definitions of all other APIs:

    Public Declare Auto Function PlaySound Lib "winmm.dll" (ByVal pszSound As String, ByVal hmod As IntPtr, ByVal fdwSound As Integer) As Boolean
Public Declare Auto Function PlaySound Lib "winmm.dll" (ByVal pszSound As Byte(), ByVal hmod As IntPtr, ByVal fdwSound As SoundFlags) As Boolean
<Flags()> _
Public Enum SoundFlags As Integer
    SND_SYNC = &H0
    SND_ASYNC = &H1
    SND_NODEFAULT = &H2
    SND_MEMORY = &H4
    SND_LOOP = &H8
    SND_NOSTOP = &H10
    SND_PURGE = &H40
    SND_NOWAIT = &H2000
    SND_ALIAS = &H10000
    SND_FILENAME = &H20000
    SND_RESOURCE = &H40004
End Enum

Public Shared Sub Play(ByVal strFileName As String)
    PlaySound(strFileName, IntPtr.Zero, SoundFlags.SND_FILENAME Or SoundFlags.SND_ASYNC)
End Sub

Public Shared Sub Play(ByVal waveData As Byte())
    'bad idea, see http://blogs.msdn.com/larryosterman/archive/2009/02/19/playsound-xxx-snd-memory-snd-async-is-almost-always-a-bad-idea.aspx
    PlaySound(waveData, IntPtr.Zero, SoundFlags.SND_ASYNC Or SoundFlags.SND_MEMORY)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ip As UIntPtr = UIntPtr.Zero
    Dim result As Boolean = PlaySound("C:\path\to\wav\file.wav", IntPtr.Zero, ip)
End Sub
0
votes

Just a complement. The Declare Lib Libname statement will search for Libname in several places if a path is not specified. winmm.dll is (and has been) part of Windows for a long time, and in most installations it resides in the "system32" folder. That's why Declare Lib "winmm.dll" simply works.