最近用MASM32编程更新SysInfo,增加对IPv6连接信息的收集,使用到了
typedef struct _MIB_TCP6ROW_OWNER_MODULE {
UCHAR ucLocalAddr[16];
DWORD dwLocalScopeId;
DWORD dwLocalPort;
UCHAR ucRemoteAddr[16];
DWORD dwRemoteScopeId;
DWORD dwRemotePort;
DWORD dwState;
DWORD dwOwningPid;
LARGE_INTEGER liCreateTimestamp;
ULONGLONG OwningModuleInfo[TCPIP_OWNING_MODULE_SIZE];
} MIB_TCP6ROW_OWNER_MODULE, *PMIB_TCP6ROW_OWNER_MODULE;
和
typedef struct _MIB_TCP6TABLE_OWNER_MODULE {
DWORD dwNumEntries;
MIB_TCP6ROW_OWNER_MODULE table[ANY_SIZE];
} MIB_TCP6TABLE_OWNER_MODULE, *PMIB_TCP6TABLE_OWNER_MODULE;
将它们转换为MASM32的定义:
;typedef struct _MIB_TCP6ROW_OWNER_MODULE {
; UCHAR ucLocalAddr[16];
; DWORD dwLocalScopeId;
; DWORD dwLocalPort;
; UCHAR ucRemoteAddr[16];
; DWORD dwRemoteScopeId;
; DWORD dwRemotePort;
; DWORD dwState;
; DWORD dwOwningPid;
; LARGE_INTEGER liCreateTimestamp;
; ULONGLONG OwningModuleInfo[TCPIP_OWNING_MODULE_SIZE];
;} MIB_TCP6ROW_OWNER_MODULE, *PMIB_TCP6ROW_OWNER_MODULE;
MIB_TCP6ROW_OWNER_MODULE STRUCT
ucLocalAddr UCHAR 16 dup (?)
dwLocalScopeId DWORD ?
dwLocalPort DWORD ?
ucRemoteAddr UCHAR 16 dup (?)
dwRemoteScopeId DWORD ?
dwRemotePort DWORD ?
dwState DWORD ?
dwOwningPid DWORD ?
liCreateTimestamp LARGE_INTEGER <>
OwningModuleInfo ULONGLONG TCPIP_OWNING_MODULE_SIZE dup(?)
MIB_TCP6ROW_OWNER_MODULE ENDS
PMIB_TCP6ROW_OWNER_MODULE typedef ptr MIB_TCP6ROW_OWNER_MODULE
;typedef struct _MIB_TCP6TABLE_OWNER_MODULE {
; DWORD dwNumEntries;
; MIB_TCP6ROW_OWNER_MODULE table[ANY_SIZE];
;} MIB_TCP6TABLE_OWNER_MODULE, *PMIB_TCP6TABLE_OWNER_MODULE;
MIB_TCP6TABLE_OWNER_MODULE STRUCT
dwNumEntries DWORD ?
table MIB_TCP6ROW_OWNER_MODULE ANY_SIZE dup(<?>)
MIB_TCP6TABLE_OWNER_MODULE ENDS
PMIB_TCP6TABLE_OWNER_MODULE typedef ptr MIB_TCP6TABLE_OWNER_MODULE
但是程序代码在汇编时出错:
error A2181: initializer must be a string or single item
第175行代码就位于MIB_TCP6TABLE_OWNER_MODULE 结构体定义代码中:
MIB_TCP6TABLE_OWNER_MODULE STRUCT ;173
dwNumEntries DWORD ? ;174
table MIB_TCP6ROW_OWNER_MODULE ANY_SIZE dup(<?>) ;175
MIB_TCP6TABLE_OWNER_MODULE ENDS ;176
这个定义 与 MASM32编写TcpStatC再进阶 显示PID和对应进程说明符 中的
MIB_TCPTABLE_OWNER_MODULE struct
dwNumEntries DWORD ?
table MIB_TCPROW_OWNER_MODULE ANY_SIZE dup(<?>)
MIB_TCPTABLE_OWNER_MODULE ends
是类似的,所以先检查了MIB_TCP6ROW_OWNER_MODULE 结构体代码定义,没有发现问题。
估计问题还是出在
table MIB_TCPROW_OWNER_MODULE ANY_SIZE dup(<?>)
这行代码本身。结构体一般有多个成员, 初始值 <?> 这种写法,用一个?号可能不妥。
于是把代码改成
table MIB_TCPROW_OWNER_MODULE ANY_SIZE dup(<>)
这次代码顺利汇编完成