【发布时间】:2009-12-07 18:12:08
【问题描述】:
我在从 DLL 调用 C 函数时遇到了一些问题,希望有人能帮助我。该函数返回 -101,它转换为“错误参数”。我传递的值是从另一个成功的函数调用返回的,所以我目前的假设是我错误地构建了结构。任何帮助表示赞赏。
函数定义为:
int sm_switch_channel_input(struct sm_switch_channel_parms *switchp)
Parameters
*switchp (a structure of the following type):
typedef struct sm_switch_channel_parms {
tSMChannelId channel; /* in */
tSM_INT st; /* in */
tSM_INT ts; /* in */
enum kSMTimeslotType type; /* in */
} SM_SWITCH_CHANNEL_PARMS;
typedef struct tSMChannelId_struct *tSMChannelId;
typedef int tSM_INT;
enum kSMTimeslotType {
kSMTimeslotTypeALaw,
kSMTimeslotTypeMuLaw,
kSMTimeslotTypeData,
};
这就是我定义和称呼它的方式...
Enum kSMTimeslotType
kSMTimeslotTypeALaw = 0
kSMTimeslotTypeMuLaw = 1
kSMTimeslotTypeData = 2
End Enum
Public Structure sm_switch_channel_input_params
<MarshalAsAttribute(UnmanagedType.SysInt)> _
Public channel As IntPtr
<MarshalAsAttribute(UnmanagedType.I4)> _
Public stream As Integer
<MarshalAsAttribute(UnmanagedType.I4)> _
Public timeslot As Integer
<MarshalAsAttribute(UnmanagedType.U4)> _
Public tsType As kSMTimeslotType
End Structure
<DllImport("TiNG.dll")> _
Private Shared Function sm_switch_channel_input_iPsCtiie1_3__(ByRef x As sm_switch_channel_input_params) As Integer
End Function
Dim sscip As sm_switch_channel_input_params
Dim err as Integer
sscip.channel = chanA
sscip.stream = streamA
sscip.timeslot = timeSlotA
sscip.tsType = kSMTimeslotType.kSMTimeslotTypeMuLaw
err = sm_switch_channel_input_iPsCtiie1_3__(sscip)
【问题讨论】:
标签: c vb.net interop marshalling