HEJ! >Har nu: Public pamxctrl As IntPtr Skall prova det. >Varför ska du göra det? MIXERCONTROL structen fylls väl i av funktionen du anropar. Det har du väl MIXERLINECONTROLS.cbmxctrl till. Dokumentationen för MIXERLINECONTROLS.pamxctrl säger Du har helt rätt! >'11 =An attempt was made to load a program with an incorrect format.API => Error 11
===
Har LÄNGE försökt att få detta att funka...
Ber nu ER om hjälp!!!
TACK!
/Alexander
Orignalet i C++ finns på:
http://support.microsoft.com/default.aspx?scid=kb;en-us;181550
REV1:
Ett problem kan vara att det skall vara en pointer här
Public pamxctrl As MIXERCONTROL ' pointer to first MIXERCONTROL array
Strukturen blir kanske för stor tycker API'n?
REV2_:
Har nu: Public pamxctrl As IntPtr
Men hur hittar man adress som en sruktur har???
<code>
Public Class Mixer
Public rc As Int32 ' Return code.
Public hMixer As Int32 ' Mixer handle used in mixer API calls.
Public mxc As New MIXERCONTROL() ' Holds the mixer control data.
Public mxl As New MIXERLINE() ' Holds the mixer line data.
Public mxlc As New MIXERLINECONTROLS() ' Obtains the mixer control.
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure MIXERCONTROL
Public cbStruct As Int32 ' size Byte of MIXERCONTROL
Public dwControlID As Int32 ' unique control id for mixer device
Public dwControlType As Int32 ' MIXERCONTROL_CONTROLTYPE_xxx
Public fdwControl As Int32 ' MIXERCONTROL_CONTROLF_xxx
Public cMultipleItems As Int32 ' if MIXERCONTROL_CONTROLF_MULTIPLE set
<VBFixedString(MIXER_SHORT_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String '* MIXER_SHORT_NAME_CHARS
<VBFixedString(MIXER_LONG_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String ' * MIXER_LONG_NAME_CHARS
Public Bounds As Double
Public Metrics As Int32
End Structure
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure MIXERLINE
Public cbStruct As Int32 ' size of MIXERLINE structure
Public dwDestination As Int32 ' zero based destinationdex
Public dwSource As Int32 ' zero based sourcedex (if source)
Public dwLineID As Int32 ' unique line id for mixer device
Public fdwLine As Int32 ' state/information about line
Public dwUser As Int32 ' driver specificformation
Public dwComponentType As Int32 ' component type line connects to
Public cChannels As Int32 ' number of channels line supports
Public cConnections As Int32 ' number of connections (possible)
Public cControls As Int32 ' number of controls at this line
<VBFixedString(MIXER_SHORT_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String '* MIXER_SHORT_NAME_CHARS
<VBFixedString(MIXER_LONG_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String '* MIXER_LONG_NAME_CHARS
Public lpTarget As Target
End Structure
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure Target
Public dwType As Int32 ' MIXERLINE_TARGETTYPE_xxxx
Public dwDeviceID As Int32 ' target device ID of device type
Public wMid As Int16 ' of target device
Public wPid As Int16 ' "
Public vDriverVersion As Int32 ' "
<VBFixedString(MAXPNAMELEN), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String ' * MAXPNAMELEN
End Structure
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure MIXERLINECONTROLS
Public cbStruct As Int32 ' size Byte of MIXERLINECONTROLS
Public dwLineID As Int32 ' line id (from MIXERLINE.dwLineID)
Public dwControl As Int32 ' MIXER_GETLINECONTROLSF_ONEBYID or MIXER_GETLINECONTROLSF_ONEBYTYPE
Public cControls As Int32 ' count of controls pmxctrl points to
Public cbmxctrl As Int32 ' size Byte of _one_ MIXERCONTROL
Public pamxctrl As MIXERCONTROL ' pointer to first MIXERCONTROL array
End Structure
Const MIXER_SHORT_NAME_CHARS As Int32 = 16
Const MIXER_LONG_NAME_CHARS As Int32 = 64
Const MAXPNAMELEN As Int32 = 32
Const MIXERLINE_COMPONENTTYPE_DST_FIRST As Int32 = &H0I
Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN As Int32 = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
Const MIXER_GETLINEINFOF_COMPONENTTYPE As Int32 = &H3I
Const MIXERCONTROL_CT_CLASS_METER As Int32 = &H10000000
Const MIXERCONTROL_CT_SC_METER_POLLED As Int32 = &H0I
Const MIXERCONTROL_CT_UNITS_SIGNED As Int32 = &H20000
Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER As Int32 = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
Const MIXERCONTROL_CONTROLTYPE_PEAKMETER As Int32 = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)
Const MIXER_GETLINECONTROLSF_ONEBYTYPE As Int32 = &H2I
Declare Function mixerOpen Lib "winmm.dll" (ByRef phmx As Int32, ByVal uMxId As Int32, ByVal dwCallback As Int32, ByVal dwInstance As Int32, ByVal fdwOpen As Int32) As Int32
Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Int32, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Int32) As Int32
Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Int32, ByRef pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Int32) As Int32
Public Sub Open()
'Open
rc = mixerOpen(hMixer, 0, 0, 0, 0)
MsgBox("mixerOpen: " & rc)
'MixerGetLineInfo
mxl.cbStruct = System.Runtime.InteropServices.Marshal.SizeOf(mxl)
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
rc = mixerGetLineInfo(hMixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
MsgBox("mixerGetLineInfo: " & rc)
'MixerGetLineControls
mxlc.cbStruct = System.Runtime.InteropServices.Marshal.SizeOf(mxlc)
mxlc.dwLineID = mxl.dwLineID
mxlc.dwControl = MIXERCONTROL_CONTROLTYPE_PEAKMETER
mxlc.cControls = 1
mxlc.cbmxctrl = System.Runtime.InteropServices.Marshal.SizeOf(mxc)
mxlc.pamxctrl = mxc
mxc.cbStruct = System.Runtime.InteropServices.Marshal.SizeOf(mxc)
rc = mixerGetLineControls(hMixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
MsgBox("mixerGetLineControls: " & rc)
'11 =An attempt was made to load a program with an incorrect format.
End Sub
End Class
</code>Sv: API => Error 11
>Men hur hittar man adress som en sruktur har???
Det är enklare om du allokerar minne med Marsha.AllocHGlobal, och lagrar den returnerade pekaren i pamxctrl. Sen, efter anropet till mixerGetLineControls, kan du använda Marsha.PtrToStructure för att läsa MIXERCONTROL informationen från din buffert, och till sist frigöra minnet med Marshal.FreeHGlobal.
MSSv: API => Error 11
Men hur skall jag kopiera in datan från strukturen till minnet som jag allokerar.
/AlexanderSv: API => Error 11
Varför ska du göra det? MIXERCONTROL structen fylls väl i av funktionen du anropar.
Hur som helst. Om du verkligen behöver göra det så använd Marshal.StructureToPtr.
MSSv: API => Error 11
Minns jag inte helt fel så skall stukturen innehålla hur många byte den är.Sv: API => Error 11
"The cbmxctrl member must specify the size, in bytes, of each element in this array. No initialization of the buffer pointed to by this member is required by the application. All members are filled in by the mixer device (including the cbStruct member of each MIXERCONTROL structure) upon returning successfully."
MSSv: API => Error 11
Så här ser koden ut nu.
Har något tid/kunskap får man GÄRNA hjälpa mig!!!
/Alexander
<code>
Public Class Mixer
Public rc As Int32 ' Return code.
Public hMixer As Int32 ' Mixer handle used in mixer API calls.
Public mxc As MIXERCONTROL ' Holds the mixer control data.
Public mxl As MIXERLINE ' Holds the mixer line data.
Public mxlc As MIXERLINECONTROLS ' Obtains the mixer control.
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure MIXERCONTROL
Public cbStruct As Int32 ' size Byte of MIXERCONTROL
Public dwControlID As Int32 ' unique control id for mixer device
Public dwControlType As Int32 ' MIXERCONTROL_CONTROLTYPE_xxx
Public fdwControl As Int32 ' MIXERCONTROL_CONTROLF_xxx
Public cMultipleItems As Int32 ' if MIXERCONTROL_CONTROLF_MULTIPLE set
<VBFixedString(MIXER_SHORT_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String '* MIXER_SHORT_NAME_CHARS
<VBFixedString(MIXER_LONG_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String ' * MIXER_LONG_NAME_CHARS
Public Bounds As Double
Public Metrics As Int32
End Structure
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure MIXERLINE
Public cbStruct As Int32 ' size of MIXERLINE structure
Public dwDestination As Int32 ' zero based destinationdex
Public dwSource As Int32 ' zero based sourcedex (if source)
Public dwLineID As Int32 ' unique line id for mixer device
Public fdwLine As Int32 ' state/information about line
Public dwUser As Int32 ' driver specificformation
Public dwComponentType As Int32 ' component type line connects to
Public cChannels As Int32 ' number of channels line supports
Public cConnections As Int32 ' number of connections (possible)
Public cControls As Int32 ' number of controls at this line
<VBFixedString(MIXER_SHORT_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String '* MIXER_SHORT_NAME_CHARS
<VBFixedString(MIXER_LONG_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String '* MIXER_LONG_NAME_CHARS
Public lpTarget As Target
End Structure
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure Target
Public dwType As Int32 ' MIXERLINE_TARGETTYPE_xxxx
Public dwDeviceID As Int32 ' target device ID of device type
Public wMid As Int16 ' of target device
Public wPid As Int16 ' "
Public vDriverVersion As Int32 ' "
<VBFixedString(MAXPNAMELEN), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String ' * MAXPNAMELEN
End Structure
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Structure MIXERLINECONTROLS
Public cbStruct As Int32 ' size Byte of MIXERLINECONTROLS
Public dwLineID As Int32 ' line id (from MIXERLINE.dwLineID)
Public dwControl As Int32 ' MIXER_GETLINECONTROLSF_ONEBYID or MIXER_GETLINECONTROLSF_ONEBYTYPE
Public cControls As Int32 ' count of controls pmxctrl points to
Public cbmxctrl As Int32 ' size Byte of _one_ MIXERCONTROL
'Public pamxctrl As MIXERCONTROL ' pointer to first MIXERCONTROL array
Public pamxctrl As IntPtr ' pointer to first MIXERCONTROL array
End Structure
Const MIXER_SHORT_NAME_CHARS As Int32 = 16
Const MIXER_LONG_NAME_CHARS As Int32 = 64
Const MAXPNAMELEN As Int32 = 32
Const MIXERLINE_COMPONENTTYPE_DST_FIRST As Int32 = &H0I
Const MIXERLINE_COMPONENTTYPE_DST_WAVEIN As Int32 = (MIXERLINE_COMPONENTTYPE_DST_FIRST + 7)
Const MIXER_GETLINEINFOF_COMPONENTTYPE As Int32 = &H3I
Const MIXERCONTROL_CT_CLASS_METER As Int32 = &H10000000
Const MIXERCONTROL_CT_SC_METER_POLLED As Int32 = &H0I
Const MIXERCONTROL_CT_UNITS_SIGNED As Int32 = &H20000
Const MIXERCONTROL_CONTROLTYPE_SIGNEDMETER As Int32 = (MIXERCONTROL_CT_CLASS_METER Or MIXERCONTROL_CT_SC_METER_POLLED Or MIXERCONTROL_CT_UNITS_SIGNED)
Const MIXERCONTROL_CONTROLTYPE_PEAKMETER As Int32 = (MIXERCONTROL_CONTROLTYPE_SIGNEDMETER + 1)
Const MIXER_GETLINECONTROLSF_ONEBYTYPE As Int32 = &H2I
Declare Function mixerOpen Lib "winmm.dll" (ByRef phmx As Int32, ByVal uMxId As Int32, ByVal dwCallback As Int32, ByVal dwInstance As Int32, ByVal fdwOpen As Int32) As Int32
Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (ByVal hmxobj As Int32, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Int32) As Int32
Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (ByVal hmxobj As Int32, ByRef pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Int32) As Int32
Public Sub Open()
'Open
rc = mixerOpen(hMixer, 0, 0, 0, 0)
'MsgBox("mixerOpen: " & rc)
'MixerGetLineInfo
mxl.cbStruct = System.Runtime.InteropServices.Marshal.SizeOf(mxl)
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN
rc = mixerGetLineInfo(hMixer, mxl, MIXER_GETLINEINFOF_COMPONENTTYPE)
'MsgBox("mixerGetLineInfo: " & rc)
'MixerGetLineControls
mxlc.cbStruct = System.Runtime.InteropServices.Marshal.SizeOf(mxlc)
mxlc.dwLineID = mxl.dwLineID
mxlc.dwControl = MIXERCONTROL_CONTROLTYPE_PEAKMETER
mxlc.cControls = 1
mxlc.cbmxctrl = System.Runtime.InteropServices.Marshal.SizeOf(mxc)
'mxc.cbStruct = System.Runtime.InteropServices.Marshal.SizeOf(mxc)
Dim p As New IntPtr()
p = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(mxc))
'System.Runtime.InteropServices.Marshal.StructureToPtr(mxc, p, True)
mxlc.pamxctrl = p
rc = mixerGetLineControls(hMixer, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
MsgBox("mixerGetLineControls: " & rc)
'11 =An attempt was made to load a program with an incorrect format.
End Sub
End Class
</code>Sv: API => Error 11
Felkod 11 betyder inte det i detta fallet, utan MMSYSERR_INVALPARAM (One or more parameters are invalid.).
Jag gissar att det beror på att MIXERCONTROL structen är för liten. Testa att definiera den såhär istället:
<code>
Structure Bounds
Public dwMinimum As Int32
Public dwMaximum As Int32
Public Reserved2, Reserved3, Reserved4, Reserved5 As Int32
End Structure
<StructLayout(LayoutKind.Explicit)> _
Structure Metrics
<FieldOffset(0)> Public cSteps As Int32
<FieldOffset(0)> Public cbCustomData As Int32
<FieldOffset(0)> Public Reserved0 As Int32
<FieldOffset(4)> Public Reserved1 As Int32
<FieldOffset(8)> Public Reserved2 As Int32
<FieldOffset(12)> Public Reserved3 As Int32
<FieldOffset(16)> Public Reserved4 As Int32
<FieldOffset(20)> Public Reserved5 As Int32
End Structure
Structure MIXERCONTROL
Public cbStruct As Int32 ' size Byte of MIXERCONTROL
Public dwControlID As Int32 ' unique control id for mixer device
Public dwControlType As Int32 ' MIXERCONTROL_CONTROLTYPE_xxx
Public fdwControl As Int32 ' MIXERCONTROL_CONTROLF_xxx
Public cMultipleItems As Int32 ' if MIXERCONTROL_CONTROLF_MULTIPLE set
<VBFixedString(MIXER_SHORT_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String '* MIXER_SHORT_NAME_CHARS
<VBFixedString(MIXER_LONG_NAME_CHARS), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String ' * MIXER_LONG_NAME_CHARS
Public Bounds As Bounds
Public Metrics As Metrics
End Structure
</code>
MS