Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: Calling Windows API from managed COBOL

$
0
0

You can still call Windows APis from managed code and you can still use TYPEDEFs such as WORD, DWORD etc but there is a problem when trying to use them as defined in windows.cpy which is not meant for use with managed code.

I defined the required typedefs directly in the program and was able to make the call that you reference in your post. You do have to load the appropriate Windows .dll containing the API call. Please see the recent post which discussed this topic here:

Example in managed code:

      $set ilpinvoke"kernel32"
       program-id.  testapi.
       environment division.
       special-names.
       call-convention 74 is WAPI.

       working-storage section.
       77 DWORD  pic 9(9) comp-5 typedef.
       77 USHORT pic 9(4) comp-5 typedef.
       77 WORD   pic 9(4) comp-5 typedef.
       77 #BYTE   pic 9(2) comp-5 typedef.
       01 VersionInfoEx.
          03 dwEVersionInfoSize        pic 9(9) comp-5.
          03 dwEMajorVersion           DWORD.
          03 dwEMinorVersion           DWORD.
          03 dwEBuildNumberFull.
             05 dwEBuildNumber         USHORT.
             05 dwEMajorAndMinor       USHORT.
          03 dwEPlatformId             DWORD.
          03 szECSDVersion             pic x(128).
          03 wEServicePackMajor        WORD.
          03 wEServicePackMinor        WORD.
          03 wESuiteMask               WORD.
          03 wEProduktType             #BYTE.
             88 ver-nt-workstation        value h"01".
             88 ver-nt-server             value h"02" h"03".
             88 ver-nt-domain-controller  value h"02".
          03 wEReserved                #BYTE.
       procedure division.
          set dwEVersionInfoSize to length of VersionInfoEx
          call WAPI "GetVersionExA" using VersionInfoEx
          goback.
           
       

Viewing all articles
Browse latest Browse all 4356

Trending Articles