非受控调用Netbios(PNCB)的问题
声明倒好办
[DllImport("netapi32.dll", CharSet=CharSet.Unicode, ExactSpelling=false, SetLastError=false)]
static unsafe extern Byte Netbios(NCB *pncb);
但是,struct NCB怎么定义?在Platform SDK中,struct NCB的定义:
typedef struct _NCB {
UCHAR ncb_command; /* command code */
UCHAR ncb_retcode; /* return code */
UCHAR ncb_lsn; /* local session number */
UCHAR ncb_num; /* number of our network name */
PUCHAR ncb_buffer; /* address of message buffer */
WORD ncb_length; /* size of message buffer */
UCHAR ncb_callname[NCBNAMSZ]; /* blank-padded name of remote */
UCHAR ncb_name[NCBNAMSZ]; /* our blank-padded netname */
UCHAR ncb_rto; /* rcv timeout/retry count */
UCHAR ncb_sto; /* send timeout/sys timeout */
void (CALLBACK *ncb_post)( struct _NCB * ); /* POST routine address */
UCHAR ncb_lana_num; /* lana (adapter) number */
UCHAR ncb_cmd_cplt; /* 0xff => commmand pending */
#ifdef _WIN64
UCHAR ncb_reserve[18]; /* reserved, used by BIOS */
#else
UCHAR ncb_reserve[10]; /* reserved, used by BIOS */
#endif
HANDLE ncb_event; /* HANDLE to Win32 event which */
/* will be set to the signalled */
/* state when an ASYNCH command */
/* completes */
} NCB, *PNCB;
怎么转成受控?
如果用[StructLayout(LayoutKind.Explicit)]和[FieldOffset(...)],UCHAR是0.5字长怎么办?
都定义成UnmanagedType或者[MarshalAs(UnmanagedType.xxx)],一执行就Crash
另外,哪位会用Marshal.StructureToPtr和Marshal.PtrToStructure?那个ncb_buffer也没解决