Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling class from form
Message
De
02/01/2013 16:25:42
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Calling class from form
Divers
Thread ID:
01561114
Message ID:
01561114
Vues:
65
.Net 2010

Hi all

Ok, stepping off into VB.Net for the first time since 2005 or so, and it's just as much fun as I remember.

Created a class, build it and added it as a reference to the project:
Public Class SoundPlayer
    Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
  As String, ByVal hmod As Integer) As Integer

'    Public Const SND_SYNC = &H0 ' play synchronously 
'    Public Const SND_ASYNC = &H1 ' play asynchronously 
'    Public Const SND_MEMORY = &H4  'Play wav in memory
'    Public Const SND_ALIAS = &H10000 'Play system alias wav 
'    Public Const SND_NODEFAULT = &H2
'    Public Const SND_FILENAME = &H20000 ' name is file name 
'    Public Const SND_RESOURCE = &H40004 ' name is resource name or atom 
End Class
And I'm trying to call it from a button on a form
    Private Sub CmdSound_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSound.Click
        Dim WaveFile As String
        Dim SndSync As Integer, SndNoDefault As Integer
        SndSync = &H0
        SndNoDefault = &H2

        WaveFile = "C:\Downloads\Sounds\uslsfact.wav"
        SoundPlayer.PlaySound(WaveFile, SndSync)
    End Sub
The form builds with no errors or warnings, but when I try to run it, I get

PInvokeStackImbalance was detected
Message: A call to PInvoke function 'WindowsApplication1!WindowsApplication1.SoundPlayer::PlaySound' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

What am I not seeing? All I need to do is create a 'hook' to the Windows Sound Player and play a .wav file. I need it in a class because I'll be using this on various forms within the application.
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform