方法:
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,哪里有专题的非托管到托管类型包装的的讨论?
谢谢

解决方案 »

  1.   

    使用命令行:tlbimp Type.dll 生成托管代码。
      

  2.   

    谢谢
    不过好象仅对com:tlbimp tlbFile tlbFile :The name of any file that contains a COM type library.
      

  3.   

    这是一个C++的代码吗?本人认为,首先把这个方法在VC++等环境下,编译为dll文件。然后再导入.net的工程即可。如何导入,方法就简单了。只要在参照进来即可。
      

  4.   

    楼上谢了
    简单点问:c++类型如何影射到managed c#类型
      

  5.   

    这是块板卡的sdk提供的dll中方法之一
      

  6.   

    你在c#中需要重新定义MTADAPTER_INFO这个struct,类型转换如下:
    ulong: uint
    UCHAR: byte
    UCHAR res[2]:
    [MarshalAs(UnmanagedType.LPArray, SizeConst=10)]byte[] res;
      

  7.   

    MT_VERSION类型的转换,需要你先给出它在dll如何被定义的
      

  8.   

    至于返回值类型,你可以用enum来定义,如下:
    public enum MT_RESULT:long
    {
        MT_RET_INVALID_PARAM = 0xE0002012L,
    }
      

  9.   


    这里还有其他一些windows内自己定义的数据类型,我如何使用啊:
    PVOID
    LARGE_INTEGER
      

  10.   

    下边这个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
    };
      

  11.   

    to PVOID
    简单点儿,就是IntPtr,如果不想用IntPtr,看看这个类型具体指向什么类型内容;to LARGE_INTEGER
    看其字节个数,
    4 bytes : int or Int32
    8 bytes : Int64
      

  12.   

    老大,我太弱,急,没时间允许我慢慢找,直接问您了
    还有问题:方法:
    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[] 要怎么弄?
      

  13.   

    to 1,方法里第二个参数是structure pointer,我传得是 ref structure ok?可以to 2 
    [MarshalAs(UnmanagedType.LPArray, SizeConst=2)]chan_ts[] associatedts;
      

  14.   

    1
    数组都用MarshalAs(UnmanagedType.LPArray, SizeConst=n)这样的模式
    而不用管它是什么类型的么?2上边的函数第二个参数是个pointer,最后那个参数是pionter to size of given buffer for ...
    有些问题,这个pointer到底是指向buffer 还是指向buffer的size我又该给他传个啥?谢谢
      

  15.   

    to PULONG CONST plength //a pointer to the size of the gaven buffer for the chan_info structureref int Length
      

  16.   

    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....
      

  17.   

    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;
    }
      

  18.   

    //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() );
      

  19.   

    为什么?
    Structure里包含还有Strucrure[] 就不能Marshal....怎么解决阿
      

  20.   

    to Structure里包含还有Strucrure[] 就不能Marshal....所出现问题的dll函数是什么样的
      

  21.   

    查了相关资料
    好像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[];
    }
      

  22.   

    竟然出现 null object reference exception;
      

  23.   

    to 竟然出现 null object reference exception;如何使用的,你需要在chan_info写一个构造函数,来初始化数组。