Highlighted
Absent Member.
Absent Member.
755 views

How to test COBOL data type hinstance returned from winapi call ?

Jump to solution

Hi there,

Hoping someone can help.

I'm calling winapi "ShellExecuteA" from a Visual Cobol program to open a document (pdf/webpage etc) which works fine. It returns a handle instance, 'hinstance' which I need to check for errors How can I move it to a field I can examine?

Windows documentation (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx) says...

"Return value - Type: HINSTANCE - If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below."

MY PROGRAM

$set ooctrl(+P)
copy "windows.cpy".

IDENTIFICATION DIVISION.
special-names.
call-convention 74 is winapi. *> Litlinked apis

WORKING-STORAGE SECTION.
01 sw-cwd pic x(1024).
01 se-hInstance HINSTANCE.


01 msgBoxText pic x(255).

LINKAGE SECTION.
01 fileToLaunch pic x(256).

PROCEDURE DIVISION using fileToLaunch.

call "cob32api".

call winapi "ShellExecuteA" using
by value 0 size 4
by reference z"open"
by reference fileToLaunch
by value 0 size 4,
by reference sw-cwd
by value SW-SHOWNORMAL
returning se-hInstance
end-call.

IF SE-HINSTANCE <= 32    *> !!!!! ILLEGAL POINTER USAGE - HOW TO DO THIS ?????
    initialize msgBoxText
    string "Unable to open the document (most likely doesn't"  
              " exist or could already be in use. File name:"
              fileToLaunch
        delimited by x'00' into msgBoxText
    call "messageBox" using msgBoxText
end-if.

goback.

 

THANK YOU,

Linden

 

 

 

Linden Rowland - IT Consultant
Owner/Developer, www.SchoolReportWriter.com
IT Consultant to Tindle Newspaper Group

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Linden,

The simplest way to do it is to add the following immediately after the definition of se-hInstance

01 se-hInstance-int int redefines se-hInstance.

where int is defined in windows.cpy, which you are already using, as pic s9(9) comp-5.

Then all you need to do is use se-hInstance-int in the comparison.

Gael.

View solution in original post

0 Likes
2 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Linden,

The simplest way to do it is to add the following immediately after the definition of se-hInstance

01 se-hInstance-int int redefines se-hInstance.

where int is defined in windows.cpy, which you are already using, as pic s9(9) comp-5.

Then all you need to do is use se-hInstance-int in the comparison.

Gael.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.
Thanks Gael, that's great, worked a treat!
Cheers,
Linden

Linden Rowland - IT Consultant
Owner/Developer, www.SchoolReportWriter.com
IT Consultant to Tindle Newspaper Group

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.