EDN Admin
Well-known member
can anyone tell me why my mciSendString callback isnt working?
the app is a console app, with a nativeWindow msgHandler class.
heres the code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Windows.Forms
<span style="color:Blue; Public <span style="color:Blue; Class msgHandler
<span style="color:Blue; Inherits NativeWindow
<span style="color:Blue; Public <span style="color:Blue; Sub <span style="color:Blue; New()
<span style="color:Blue; Me.CreateHandle(<span style="color:Blue; New CreateParams)
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Protected <span style="color:Blue; Overrides <span style="color:Blue; Sub WndProc(<span style="color:Blue; ByRef m <span style="color:Blue; As System.Windows.Forms.Message)
<span style="color:Blue; Const MM_MCINOTIFY <span style="color:Blue; As <span style="color:Blue; Integer = &H3B9
<span style="color:Blue; Const MCI_NOTIFY_SUCCESSFUL <span style="color:Blue; As <span style="color:Blue; Integer = &H1
<span style="color:Blue; Const MCI_NOTIFY_ABORTED <span style="color:Blue; As <span style="color:Blue; Integer = &H4
<span style="color:Blue; Const MCI_NOTIFY_FAILURE <span style="color:Blue; As <span style="color:Blue; Integer = &H8
<span style="color:Blue; Const MCI_NOTIFY_SUPERSEDED <span style="color:Blue; As <span style="color:Blue; Integer = &H2
<span style="color:Blue; Select <span style="color:Blue; Case (m.Msg)
<span style="color:Green; The WM_ACTIVATEAPP message occurs when the application
<span style="color:Green; becomes the active application or becomes inactive.
<span style="color:Blue; Case MM_MCINOTIFY
<span style="color:Green; The WParam.ToInt32 identifies what is occurring.
<span style="color:Green; Note: mLParam.ToInt64 is DeviceID
<span style="color:Green; Dim result As PlayResult
<span style="color:Blue; Select <span style="color:Blue; Case m.WParam.ToInt32()
<span style="color:Blue; Case MCI_NOTIFY_SUCCESSFUL
<span style="color:Green; The conditions initiating the callback function
<span style="color:Green; have been met.
<span style="color:Green; result = PlayResult.Successful
<span style="color:Blue; Case MCI_NOTIFY_ABORTED
<span style="color:Green; The device received a command that prevented
<span style="color:Green; the current conditions for initiating the callback function from being met.
<span style="color:Green; If a new command interrupts the current command and it also requests
<span style="color:Green; notification, the device sends this message only and not
<span style="color:Green; result = PlayResult.Aborted
<span style="color:Blue; Case MCI_NOTIFY_SUPERSEDED
<span style="color:Green; result = PlayResult.Superseded
<span style="color:Blue; Case MCI_NOTIFY_FAILURE
<span style="color:Green; A device error occurred while the device was
<span style="color:Green; executing the command.
<span style="color:Green; result = PlayResult.DeviceFailure
<span style="color:Blue; Case <span style="color:Blue; Else
<span style="color:Green; result = PlayResult.Unknown
<span style="color:Blue; End <span style="color:Blue; Select
<span style="color:Blue; End <span style="color:Blue; Select
Debug.Print(m.ToString)
<span style="color:Blue; MyBase.WndProc(m)
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
this is the console module:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Module Module1
<span style="color:Green; Api to send the commands to the mci device.
<span style="color:Blue; Private <span style="color:Blue; Declare <span style="color:Blue; Function mciSendString <span style="color:Blue; Lib <span style="color:#A31515; "winmm.dll" <span style="color:Blue; Alias <span style="color:#A31515; "mciSendStringA" _
(<span style="color:Blue; ByVal lpstrCommand <span style="color:Blue; As <span style="color:Blue; String, <span style="color:Blue; ByVal lpstrReturnString <span style="color:Blue; As <span style="color:Blue; String, <span style="color:Blue; ByVal uReturnLength <span style="color:Blue; As _
<span style="color:Blue; Integer, <span style="color:Blue; ByVal hwndCallback <span style="color:Blue; As <span style="color:Blue; Integer) <span style="color:Blue; As <span style="color:Blue; Integer
<span style="color:Blue; Sub Main()
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) & <span style="color:#A31515; ")
Console.WriteLine(<span style="color:#A31515; "")
Console.WriteLine(<span style="color:#A31515; "<dir>")
<span style="color:Blue; For <span style="color:Blue; Each file <span style="color:Blue; As <span style="color:Blue; String <span style="color:Blue; In IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), <span style="color:#A31515; "*.mp3")
Console.WriteLine(IO.Path.GetFileName(file))
<span style="color:Blue; Next
Console.WriteLine(<span style="color:#A31515; "")
<span style="color:Blue; Dim mh <span style="color:Blue; As <span style="color:Blue; New msgHandler
<span style="color:Blue; Dim _fileToPlay <span style="color:Blue; As <span style="color:Blue; String = Chr(34) + IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), Console.ReadLine) + Chr(34)
mciSendString(<span style="color:#A31515; "open " & _fileToPlay & <span style="color:#A31515; " alias myDevice notify", <span style="color:Blue; Nothing, 0, mh.Handle.ToInt32)
mciSendString(<span style="color:#A31515; "play myDevice notify", <span style="color:Blue; Nothing, 0, mh.Handle.ToInt32)
Console.ReadLine()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Module
[/code]
<hr class="sig thanks for any help
View the full article
the app is a console app, with a nativeWindow msgHandler class.
heres the code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Windows.Forms
<span style="color:Blue; Public <span style="color:Blue; Class msgHandler
<span style="color:Blue; Inherits NativeWindow
<span style="color:Blue; Public <span style="color:Blue; Sub <span style="color:Blue; New()
<span style="color:Blue; Me.CreateHandle(<span style="color:Blue; New CreateParams)
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Protected <span style="color:Blue; Overrides <span style="color:Blue; Sub WndProc(<span style="color:Blue; ByRef m <span style="color:Blue; As System.Windows.Forms.Message)
<span style="color:Blue; Const MM_MCINOTIFY <span style="color:Blue; As <span style="color:Blue; Integer = &H3B9
<span style="color:Blue; Const MCI_NOTIFY_SUCCESSFUL <span style="color:Blue; As <span style="color:Blue; Integer = &H1
<span style="color:Blue; Const MCI_NOTIFY_ABORTED <span style="color:Blue; As <span style="color:Blue; Integer = &H4
<span style="color:Blue; Const MCI_NOTIFY_FAILURE <span style="color:Blue; As <span style="color:Blue; Integer = &H8
<span style="color:Blue; Const MCI_NOTIFY_SUPERSEDED <span style="color:Blue; As <span style="color:Blue; Integer = &H2
<span style="color:Blue; Select <span style="color:Blue; Case (m.Msg)
<span style="color:Green; The WM_ACTIVATEAPP message occurs when the application
<span style="color:Green; becomes the active application or becomes inactive.
<span style="color:Blue; Case MM_MCINOTIFY
<span style="color:Green; The WParam.ToInt32 identifies what is occurring.
<span style="color:Green; Note: mLParam.ToInt64 is DeviceID
<span style="color:Green; Dim result As PlayResult
<span style="color:Blue; Select <span style="color:Blue; Case m.WParam.ToInt32()
<span style="color:Blue; Case MCI_NOTIFY_SUCCESSFUL
<span style="color:Green; The conditions initiating the callback function
<span style="color:Green; have been met.
<span style="color:Green; result = PlayResult.Successful
<span style="color:Blue; Case MCI_NOTIFY_ABORTED
<span style="color:Green; The device received a command that prevented
<span style="color:Green; the current conditions for initiating the callback function from being met.
<span style="color:Green; If a new command interrupts the current command and it also requests
<span style="color:Green; notification, the device sends this message only and not
<span style="color:Green; result = PlayResult.Aborted
<span style="color:Blue; Case MCI_NOTIFY_SUPERSEDED
<span style="color:Green; result = PlayResult.Superseded
<span style="color:Blue; Case MCI_NOTIFY_FAILURE
<span style="color:Green; A device error occurred while the device was
<span style="color:Green; executing the command.
<span style="color:Green; result = PlayResult.DeviceFailure
<span style="color:Blue; Case <span style="color:Blue; Else
<span style="color:Green; result = PlayResult.Unknown
<span style="color:Blue; End <span style="color:Blue; Select
<span style="color:Blue; End <span style="color:Blue; Select
Debug.Print(m.ToString)
<span style="color:Blue; MyBase.WndProc(m)
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
this is the console module:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Module Module1
<span style="color:Green; Api to send the commands to the mci device.
<span style="color:Blue; Private <span style="color:Blue; Declare <span style="color:Blue; Function mciSendString <span style="color:Blue; Lib <span style="color:#A31515; "winmm.dll" <span style="color:Blue; Alias <span style="color:#A31515; "mciSendStringA" _
(<span style="color:Blue; ByVal lpstrCommand <span style="color:Blue; As <span style="color:Blue; String, <span style="color:Blue; ByVal lpstrReturnString <span style="color:Blue; As <span style="color:Blue; String, <span style="color:Blue; ByVal uReturnLength <span style="color:Blue; As _
<span style="color:Blue; Integer, <span style="color:Blue; ByVal hwndCallback <span style="color:Blue; As <span style="color:Blue; Integer) <span style="color:Blue; As <span style="color:Blue; Integer
<span style="color:Blue; Sub Main()
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic) & <span style="color:#A31515; ")
Console.WriteLine(<span style="color:#A31515; "")
Console.WriteLine(<span style="color:#A31515; "<dir>")
<span style="color:Blue; For <span style="color:Blue; Each file <span style="color:Blue; As <span style="color:Blue; String <span style="color:Blue; In IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), <span style="color:#A31515; "*.mp3")
Console.WriteLine(IO.Path.GetFileName(file))
<span style="color:Blue; Next
Console.WriteLine(<span style="color:#A31515; "")
<span style="color:Blue; Dim mh <span style="color:Blue; As <span style="color:Blue; New msgHandler
<span style="color:Blue; Dim _fileToPlay <span style="color:Blue; As <span style="color:Blue; String = Chr(34) + IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), Console.ReadLine) + Chr(34)
mciSendString(<span style="color:#A31515; "open " & _fileToPlay & <span style="color:#A31515; " alias myDevice notify", <span style="color:Blue; Nothing, 0, mh.Handle.ToInt32)
mciSendString(<span style="color:#A31515; "play myDevice notify", <span style="color:Blue; Nothing, 0, mh.Handle.ToInt32)
Console.ReadLine()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Module
[/code]
<hr class="sig thanks for any help
View the full article