我正在调用Windows API Getsysteminfo()
来获取系统信息。
但是,SYSTEM_INFO
结构不会填充正确的信息。
我认为主要的嫌疑人是成员dwActiveProcessorMask因为它的事实
可以编译为32位或64位平台。我将其定义为32位签名
整数。以下是COBOL
代码:
identification division.
program-id. TEST.
Environment Division.
CONFIGURATION SECTION.
special-names.
call-convention 74 is WinAPI.
working-storage section.
01 DWORD pic 9(9) comp-5 value 0 typedef.
01 WORD pic 9(5) comp-5 value 0 typedef.
01 LPVOID POINTER typedef.
01 DWORD-PTR POINTER typedef.
01 SYSTEM-INFO.
05 dwOemId DWORD.
05 wProcessorArchitecture WORD.
05 wReserved WORD.
05 dwPageSize DWORD.
05 lpMinimumApplicationAddress LPVOID.
05 lpMaximumApplicationAddress LPVOID.
05 dwActiveProcessorMask DWORD-PTR.
05 dwNumberOfProcessors DWORD.
05 dwProcessorType DWORD.
05 dwAllocationGranularity DWORD.
05 wProcessorLevel WORD.
05 wProcessorRevision WORD.
linkage section.
01 LS-DWORD-PTR DWORD.
procedure division WinApi.
100-MAIN SECTION 1.
call winapi "GetSystemInfo" using
by reference System-Info
end-call
set address of ls-dword-ptr to dwActiveProcessorMask
感谢您的帮助......
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724381(v=vs.85).aspx
答案 0 :(得分:2)
我做这些事已经20年了;但我记得在C pointer
中没有直接的方法可以“取消引用”COBOL
。必须间接完成。
变化:
01 DWORD-PTR pic s9(9) comp-5 value 0 typedef.
到
01 DWORD-PTR POINTER typedef.
添加:
linkage section.
01 ls-dword DWORD.
在call
添加:
set address of ls-dword to dwActiveProcessorMask
在set
语句后,ls-dword
的内容将与dwActiveProcessorMask
的内容相同。
(在2002年的标准中,添加了BASED
子句来处理这些情况。)
这是SYSTEM_INFO
的第一部分。
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
您定义为:
05 dwOemId DWORD.
05 wProcessorArchitecture WORD.
05 wReserved WORD.
05 dwPageSize DWORD.
在COBOL中,C
union
变为REDEFINES
,即wProcessorArchitecture
,wReserved
占用与dwOemId
相同的空格。由于dwOemId
已过时,因此应将其删除。实际上SYSTEM-INFO
比它应该长4个字节。