怎样 import 这个函数

32757487 2006-06-27 03:05:15
方法:
MT_RESULT MTGetAdapterInfo(const BOARD nboard,PMTADAPTER_INFO const pBoardInfo,PULONG const pLength);

参数说明:
nboard :board number
pBoardInfo :pointer to MTADAPTER_INFO structure
pLength :Set by the user application, this is a pointer to the size of the given buffer
for the MTADAPTER_INFO structure.

Structure定义说明:
MTADAPTER_INFO structure is defined as follows:
public struct MTADAPTER_INFO
{
ulong Status; // Status value of BOARD_OK, etc.
ulong BoardNumber; // Board index in SDK, i.e. SystemIndex
MT_VERSION FWVersion; // On board firmware version
ulong BaseAddress; // I/O base address
ulong Interrupt; // Interrupt number
ulong StartChannel; // Logical # of the 1st on board channel
ulong Channels; // Number of channels on the board
ulong Option1; // Basic Board option
// option 1
// bit 0 WAV
// bit 1 MVIP
// bit 2 Volume/Pitch
// bit 3 MF
// bit 4 Silence Compression
ulong Option2; // Extended Board option
// option 2
// bit 0 Caller ID
// bit 1 Conference
// bit 2 Call Logging
// bit 4 FAX
// bit 6 Pulse detection
ulong Digirate; // Digitizing rate
ulong Bandwidth; // Channel bandwidth
ulong PCISlot;
ulong PCIBusNumber;

ulong BoardType; // Board Type of DUAL_T1_PASSIVE_HI_CARD, etc.

UCHAR BusType; // MUX_H100, MUX_MVIP, or MUX_NONE
UCHAR MasterMode; // Board Master Mode of the following:
// 0 slave board
// 1 MVIP master, or H100 Master A
// 2 H100 Master B
UCHAR MasterClock; // Master clock source reference value
// of CLOCK_SOURCE_OSC, and etc.
UCHAR Sec8kNetrefClock; // MVIP Sec8K or H100 Netref clock output
// 0 Disabled, output tri-stated
// 1, 3 - 4 Type of clock reference of
// CLOCK_SOURCE_OSC, etc.
UCHAR NumSummations; // Number of summation resource on board, if any
UCHAR StartSummation; // Index of the first on board summation resource
UCHAR NumAudios; // Number of audio jack resource on board, if any
UCHAR StartAudio; // Index of the first on board audio jack resource
UCHAR TDMSignaling; // CT TDM bus signaling: 0 for u-law, 1 for A-law
UCHAR ConfigurationId; // Adapter Configuration Index (i.e. SwitchIndex)
UCHAR res[2];
MT_VERSION FWVersionExpected; // Expected on board firmware version
}

函数返回值:
MT_RET_OK No error
MT_RET_INVALID_PARAM Invalid argument passed to function
MT_RET_INVALID_BOARD Board number is out of range
MT_RET_NOT_AVAILABLE Driver is not loaded


我想知道的问题是:
1,他的返回值是自定的key值(.h中的定义之一:#define MT_RET_INVALID_PARAM 0xE0002012L),我应该用什么托管类型来与之对应?
2,他所有的自定义类型我都必须建立与之对应的托管版本么?
3,”a pointer to the size of the given buffer“ 这个buffer我应该用什么托管类型代替?
4,哪里有专题的非托管到托管类型包装的的讨论?


谢谢
...全文
409 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
Knight94 2006-07-02
  • 打赏
  • 举报
回复
to 竟然出现 null object reference exception;

如何使用的,你需要在chan_info写一个构造函数,来初始化数组。
32757487 2006-07-02
  • 打赏
  • 举报
回复
竟然出现 null object reference exception;
32757487 2006-07-02
  • 打赏
  • 举报
回复
查了相关资料
好像c#对c-style arry的支持不很好,好像仅ByValArry有用。

出问题的dll函数需要一个上边的自定义的structure的pionter 参数,
刚好,这个structure里又有structure数组

我现在参考别人的做法,把这个field :stucture[]替换成等同长度[bit位]的byte
上边这个长度是
typpedef struct chan_info
{
ulong type; //32
chan_ts associatedts[2] //16*4
}
typedef struct chan_ts
{
short id; //16bit
short name; //16bit
}

替换成如下:

public struct chan_info
{
pubic uint type;
[MarshalAs(UnmanagedType.ByValArry,ConstSize=4)//4 byte
public byte[];
}

Knight94 2006-07-01
  • 打赏
  • 举报
回复
to Structure里包含还有Strucrure[] 就不能Marshal....

所出现问题的dll函数是什么样的
32757487 2006-07-01
  • 打赏
  • 举报
回复
为什么?
Structure里包含还有Strucrure[] 就不能Marshal....

怎么解决阿
Knight94 2006-06-30
  • 打赏
  • 举报
回复
to PULONG CONST plength //a pointer to the size of the gaven buffer for the chan_info structure

ref int Length
32757487 2006-06-30
  • 打赏
  • 举报
回复
1
数组都用MarshalAs(UnmanagedType.LPArray, SizeConst=n)这样的模式
而不用管它是什么类型的么?

2

上边的函数第二个参数是个pointer,最后那个参数是pionter to size of given buffer for ...
有些问题,这个pointer到底是指向buffer 还是指向buffer的size

我又该给他传个啥?

谢谢
Knight94 2006-06-30
  • 打赏
  • 举报
回复
to 1,方法里第二个参数是structure pointer,我传得是 ref structure ok?

可以

to 2
[MarshalAs(UnmanagedType.LPArray, SizeConst=2)]chan_ts[] associatedts;
32757487 2006-06-30
  • 打赏
  • 举报
回复
老大,我太弱,急,没时间允许我慢慢找,直接问您了
还有问题:

方法:
MtGetInfor(
const channel,//ulong channel number
PMTCHAN_INFO const pchannel_info,//a pointer to chan_info structure
PULONG CONST plength //a pointer to the size of the gaven buffer for the chan_info structure

structure:
typpedef struct chan_info
{
ulong type;
chan_ts associatedts[2] //结构数组,这玩意怎么搞?
}
typedef struct chan_ts
{
short id;
short name;
}
想知道:
1,方法里第二个参数是structure pointer,我传得是 ref structure ok?
2,structure[] 要怎么弄?
32757487 2006-06-30
  • 打赏
  • 举报
回复
还是一样~
Knight94 2006-06-30
  • 打赏
  • 举报
回复
//calling
chan_info mychan_info = new chan_info( 1 );
MessageBox.Show( mychan_info.type.ToString() );
MessageBox.Show( mychan_info.associatedts[0].ToString() );
MessageBox.Show( mychan_info.associatedts[1].ToString() );
Knight94 2006-06-30
  • 打赏
  • 举报
回复
Sample code as follows:
public struct chan_info
{
public uint type;
[MarshalAs(UnmanagedType.LPArray, SizeConst=2)]
public chan_ts[] associatedts;
public chan_info( uint typevalue )
{
type = typevalue;
associatedts = new chan_ts[2];
for( int i = 0; i < 2; i++ )
associatedts[i] = new chan_ts();
}
}

public struct chan_ts
{
public short id;
public short name;
}
32757487 2006-06-30
  • 打赏
  • 举报
回复
运行的时候
Knight94 2006-06-30
  • 打赏
  • 举报
回复
你是编译不通过,还是运行呢
32757487 2006-06-30
  • 打赏
  • 举报
回复
hi ,老大
我按照你的提示做,得到提示

can not marshal filed associatedts of type chan_ts :this type can not be marshaled as structure filed.





tell me why and how to solve it please.

thks a lot....
Knight94 2006-06-28
  • 打赏
  • 举报
回复
to PVOID
简单点儿,就是IntPtr,如果不想用IntPtr,看看这个类型具体指向什么类型内容;

to LARGE_INTEGER
看其字节个数,
4 bytes : int or Int32
8 bytes : Int64
32757487 2006-06-27
  • 打赏
  • 举报
回复
下边这个Struct内
(已经修改为managed版本,除了两个winnt 数据类型:LARGE_INTEGER PVOID):

public struct MT_EVENT
{

LARGE_INTEGER TimeStamp; // In FILETIME format
public uint UserStatus; // Not used by API
public uint EventCode; // Event Code
public uint SubReason; // Event sub-reason
public uint XtraInfo; // Extra information, e.g. termination
public uint FuncCode; // Function active when this event occurred
public UInt16 Board; // Board ID
public UInt16 Channel; // Global Channel ID (GCI)
PVOID ptrBuffer; // Related play/record buffer pointer
public uint DataLength; // Byte length of data accessed (played/recorded)

PVOID ptrXtraBuffer; // Pointer to xtra buffer
public uint XtraBufferLength; // Length of buffer pointed by ptrXtraBuffer
public uint XtraDataLength; // Length of data in buffer pointed by ptrXtraBuffer
public uint EventFlag; // Falgs of the following:
// bit 0x00000001: 1 - Appl created the event
// 0 - NTi DLL created the event
// bit 0x00000002: 1 - Appl allocated ptrtraBuffer
// 0 - NTi DLL allocated ptrXtraBuffer
};
32757487 2006-06-27
  • 打赏
  • 举报
回复

这里还有其他一些windows内自己定义的数据类型,我如何使用啊:
PVOID
LARGE_INTEGER
32757487 2006-06-27
  • 打赏
  • 举报
回复
谢谢
马上开工试验~
Knight94 2006-06-27
  • 打赏
  • 举报
回复
至于返回值类型,你可以用enum来定义,如下:
public enum MT_RESULT:long
{
MT_RET_INVALID_PARAM = 0xE0002012L,
}
加载更多回复(8)

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧