Highlighted
Absent Member.
Absent Member.
984 views

[archive] InternetCheckConnection Api

[Migrated content. Thread originally posted on 17 December 2004]

Good Days,

Im trying to get working InternetCheckConnection Api, but something is wrong.

This is my code:

77 Flags PIC 9(9) USAGE IS COMP-5.
77 Reserved PIC 9(9) USAGE IS COMP-5.
77 Boolean PIC 9(9) USAGE IS COMP-5.

set environment "dll-convention" to 1
set environment "code_prefix" to "."

move zeroes to Reserved

call "wininet.dll"
call "InternetCheckConnectionA" using "http://www.terra.es", flags, Reserved
giving Boolean
cancel "wininet.dll"

This is the function i want to call:

Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

All works well, it found the dll, found the function and in runtime it take a while to give me the value, like the function is connecting, but if the URL exist or not always return me a value of 0.

dwFlags can be set to FLAG_ICC_FORCE_CONNECTION but i dont know how exactly set this value in cobol or the correct pictures of variables.

Here there is more information:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/internetcheckconnection.asp

Can someone help me?

Thank you very much
0 Likes
5 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] InternetCheckConnection Api

The mistake is passing a literal instead of a pointer. It's a common mistake when calling dll's from acucobol, I used to do it too! But Gisle's Advanced Windows Programming class educated me on the right way to do it. Thanks Gisle!

What's happening is that in your CALL statement your attempting to pass a literal for the URL, but the function actually wants a pointer(the address in memory) to a string. Also, the help page mentions that the string must be null terminated(this helps the function to indentify the end of the url in the string).

When you see an "lp" prefix in front of the data type, it means a long pointer. This means you must place your value into a working storage variable, and then in your CALL statement, use BY REFERENCE for the data item. This will pass the value of the address of the data item in memory instead of a copy of the actual data item.

For example:

WORKING-STORAGE.
77 Flags PIC 9(9) USAGE IS COMP-5.
77 Reserved PIC 9(9) USAGE IS COMP-5.
77 Boolean PIC 9(9) USAGE IS COMP-5.
|string for URL
77 Url PIC X(255) VALUE SPACES.

PROCEDURE-DIVISION.
set environment "dll-convention" to 1
set environment "code_prefix" to "."

move zeroes to Reserved, Flags.
move "http://www.terra.es" to Url.
|null terminate URL
inspect Url replacing trailing space by null.

call "wininet.dll"
call "InternetCheckConnectionA" using
   by reference Url,
   by value Flags,
   by value Reserved
   giving Boolean.
cancel "wininet.dll"
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] InternetCheckConnection Api

thanks for the tips about calling correctly an Api, that resolve a bunch of doubts i had.

But the api still giving me zero, no matter if exist or not the url. I think the problem is in the flag of that api, FLAG_ICC_FORCE_CONNECTION, dunno which is the value of that flag or how i can pass it in cobol.

Someone have succesfully use the Api? because dont know if maybe is a problem in my system.

Windows 2000 service pack 3, with a correct connection to internet through a lan

Thanks
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] InternetCheckConnection Api

Originally posted by ciacsl
But the api still giving me zero, no matter if exist or not the url.


This code works. If you compile and run this, you will get a return code 0 (FALSE). If you change the domain from .no to .com you will get a return code of 1 (TRUE).


       IDENTIFICATION               DIVISION.
       PROGRAM-ID.                  TEMPLATE.
       ENVIRONMENT                  DIVISION.
       CONFIGURATION                SECTION.
       SPECIAL-NAMES.
       WORKING-STORAGE SECTION.
       77 urlBuffer                 PIC X(100).
       77 dwFlags                   PIC 9(9) COMP-5.
       77 dwReserved                PIC 9(9) COMP-5.
       77 dwResult                  PIC S9(9) COMP-5.
       77 visResult                 PIC -------9.

       PROCEDURE DIVISION.
       MAIN-LOGIC.

           STRING  "HTTP://WWW.ACUCORP.NO" DELIMITED BY SPACE
                   LOW-VALUES      DELIMITED BY SIZE
                   INTO            urlBuffer.
           MOVE    1               TO dwFlags.
           INITIALIZE              dwReserved
                                   dwResult.
           SET     ENVIRONMENT     "DLL-CONVENTION" TO "1".
           CALL    "WININET.DLL"
           CALL    "InternetCheckConnectionA" USING
                   BY REFERENCE    urlBuffer
                   BY VALUE        dwFlags
                   BY VALUE        dwReserved
                   GIVING          dwResult.
           MOVE    dwResult        TO visResult.
           DISPLAY MESSAGE         BOX
                   visResult
                   TITLE           "Internet control"
                   TYPE            1.
           CANCEL  "wininet.dll".
           EXIT    PARAGRAPH.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] InternetCheckConnection Api

it works now! thanks a lot, the problem were i didn't put the low-values at the end of the url string.

Thanks a lot to both 😄
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] InternetCheckConnection Api

Also, as gisle shows in his code, it is a good idea to initialize or set a default value for other paramaters being passed:


MOVE 1 TO dwFlags. | FLAG_ICC_FORCE_CONNECTION = &H1
INITIALIZE dwReserved, dwResult.


I say this because working storage not initialized with a valid value may cause strange results in API functions.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.