hallo buchel,
du kannst mich jederzeit über icq erreichen !
hier
http://www.thescripts.com/forum/thread367450.html
kann man folgende message lesen
Hi,
I would try changing the lpData to a string in the structure. Also
i would change lpnext to an intptr. Use Marshal.PtrtoStructure to get the
data from lpnext. Hope that helps.
Ken
------------------
"Reinier VDW" <ReinierVDW@discussions.microsoft.com> wrote in message
news:A74407D4-E1F4-43F1-9681-AB453C9968E2@microsoft.com...
Hi Ken,
Please find below some coding:
__________________________________________________ _____
Public Declare Function midiInOpen Lib "winmm.dll" (ByRef lphMidiIn As
Integer, _
ByVal uDeviceID As Integer, ByVal lpFunction As MidiRecordDelegate, _
ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer
Public Declare Function midiInStart Lib "winmm.dll" (ByVal hMidiIn As
Integer) _
As Integer
Public Declare Function midiInAddBuffer Lib "winmm.dll" (ByVal hMidiIn As
Integer, _
ByRef lpMidiInHdr As MIDIHDR, ByVal uSize As Integer) As Integer
Public Declare Function midiInPrepareHeader Lib "winmm.dll" _
(ByVal hMidiIn As Integer, ByRef lpMidiInHdr As MIDIHDR, ByVal uSize As
Integer) _
As Integer
Delegate Function MidiRecordDelegate(ByVal hMidiIn As Integer, _
ByVal dwMsg As Integer, ByVal dwInstance As Integer, ByVal lParam1 As
Integer, _
ByVal lParam2 As Integer) As Integer
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Structure MIDIHDR
Dim lpData As Integer
Dim dwBufferLength As Integer
Dim dwBytesRecorded As Integer
Dim dwUser As Integer
Dim dwFlags As Integer
Dim lpNext As Integer
Dim Reserved As Integer
End Structure
Public mhdr() As MIDIHDR
Public CallBRec As MidiRecordDelegate
Public Const MIM_DATA As Integer = &H3C3
Public Const MIM_LONGDATA As Integer = &H3C4
Public Function MidiRecord(ByVal hMidiIn As Integer, ByVal dwMsg As
Integer, _
ByVal dwInstance As Integer, ByVal lParam1 As Integer, _
ByVal lParam2 As Integer) As Integer
' this is the callback function
Select Case dwMsg
Case MIM_DATA
' process short message
Case MIM_LONGDATA
' process long message
End Select
End Function
__________________________________________________ _________________
The midi input port is opened by a call to midiInOpen:
CallBRec = New MidiRecordDelegate(AddressOf MidiRecord)
lRet = midiInOpen(hMidiIn, uDevInID, CallBRec, 0, &H30000)
which delivers the handle hMidiIn.
A series of 10 buffers is prepared (midiInPrepareHeader) and passed to the
driver
by midiInAddBuffer:
ReDim mhdr(10)
ReDim bMsg(10 * lenMsg)
For i = 0 To 9
myHandle = GCHandle.Alloc(bMsg(i * lenMsg), GCHandleType.Pinned)
mhdr(i).lpData = myHandle.AddrOfPinnedObject.ToInt32
mhdr(i).dwBufferLength = lenMsg
mhdr(i).dwFlags = 0
lRet = midiInPrepareHeader(hMidiIn, mhdr(i), Len(mhdr(i)))
lRet = midiInAddBuffer(hMidiIn, mhdr(i), Len(mhdr(i)))
Next i
The midiInStart function starts MIDI input on the specified MIDI input
device:
lRet = midiInStart(hMidiIn)
When midi data are detected by the driver the above sub MidiRecord is
called; dwMsg contains the type of the message (short or long) and lParam1
and lParam2 the actual data.
System-exclusive (long) messages are placed in the buffers supplied by the
midiInAddBuffer function, i.e. in the buffers where lpData points to, i.e.
bMsg.
When running the code and sending a signal to the midiport it appears that
MidiRecord is called, the message MIM_LONGDATA is received (all as usual
with VB6), but the array bMsg remains empty. I had the idea that the pointer
to the structure or that to bMsg is incorrect, but how should I detect that?
Thanks a lot for your help!
Reinier gruss
mikeb69 |