非受控调用Netbios(PNCB)的问题

fangzhe 2003-12-08 04:53:10
声明倒好办
[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也没解决
...全文
95 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fangzhe 2003-12-11
  • 打赏
  • 举报
回复
谢谢思归
saucer 2003-12-09
  • 打赏
  • 举报
回复
take a look at

http://groups.google.com/groups?q=dllimport++Netbios++NCB&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OdX4NLUGDHA.2176%40TK2MSFTNGP10.phx.gbl&rnum=2

110,538

社区成员

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

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

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