COBOL - 调用Windows API Getsysteminfo()

时间:2018-05-23 14:35:19

标签: windows cobol

我正在调用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

1 个答案:

答案 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,即wProcessorArchitecturewReserved占用与dwOemId相同的空格。由于dwOemId已过时,因此应将其删除。实际上SYSTEM-INFO比它应该长4个字节。