Highlighted
Absent Member.
Absent Member.
465 views

"Call winapi..." fails in chained-to prog, works in called prog?

Hi,

CALL WINAPI "MessageBoxA", gets windows "114 Attempt to access item beyond bounds of memory:" when I CHAIN to prog below but works if I CALL the prog.

I want to chain to it when a db error occurs so that all resources are freed (file locks etc) even if user doesn't close my pop up box. I'm running within Visual studio i.e. in development environment.

I'm using Visual COBOL / Windows 10.

Thanks, Linden

 

environment division.
special-names.
call-convention 74 is winapi.
data division.
working-storage section.
01 retCode pic x(4) comp-5 value zero.
01 msgCaption pic x(255) value
z"TNL Advertising Management System Error Report".
01 uType pic x(4) comp-5 value 273. *> 305.
01 msgText pic x(1000).
01 username pic x(100).

linkage section.
01 callersMsgText pic x(1000).
procedure division using callersMsgText.

*> IF HERE THIS PROG HAS BEEN CHAINED TO, NOT CALLED, SO
*> THAT RESOURCES HELD BY CALLING PROG ARE RELEASED BEFORE
*> ABORT MSG SHOWN. HENCE IF USER DOESN'T CLOSE THIS MSG BOX
*> NO FILES ARE HELD OPEN ETC.
display 'USERNAME' upon environment-name.
accept username from environment-value.

string 'AN ERROR OCCURRED.' x'0d0a0d0a'
'PLEASE email screen print to:' x'0d0a'
'Linden Rowland ('
'TNL Ad. Management System developer)' x'0d0a'
'lindenrowland@yahoo.com'
' or contact Tindle IT.' x'0d0a0d0a'
'DETAILS:' x'0d0a'
'Windows account name: ' username x'0d0a'
callersMsgText(1:900)
x'0d0a0d0a'
'CLICK OK. TNL Ad. Management System will shut down.'
x'00'
delimited by ' ' into msgText.

initialize retCode.
perform until retCode = 1
call WINAPI "MessageBoxA"
using by value 0 size 4
by reference msgText, msgCaption
by value uType
returning retCode
end-call
end-perform.

STOP RUN.

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

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: "Call winapi..." fails in chained-to prog, works in called prog?

I cannot get this to fail.

Can you please tell me what type of executable formats you are using, i.e, .int, .gnt, or .EXE?
Is this x86 or x64?
Are these two programs in the same project or in different projects?
Are you linking in the user32.lib into each program or are you not doing this?
What product version are you using?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: "Call winapi..." fails in chained-to prog, works in called prog?

Hi Chris,
Thanks for reply.
Using int/gnt compiled/linked into single .exe for production. x86 I think - see screenprint attached. I'm using visual cobol 3.0 - not easy for us to update as involves updating all production environments. If you think it may be an issue with our version then I'll need to retest at a later time.
OTHERWISE... can you suggest an alternative method. Basically i want to branch to an error routine and release all resources before display info window.
ALSO... is there a way to timeout an MF dialog session globally i.e. without having to put code in every bit of dialog separately?
Thanks,
Linden

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

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: "Call winapi..." fails in chained-to prog, works in called prog?

I cannot get it to fail with VC 3.0 either. You might have to load in the Windows User32.dll at the beginning of the program that is creating the MessageBox.
01 pp procedure-pointer.
set pp to entry "User32"

Letting the run-time system clean up open resources in your application by issuing a CHAIN is certainly not the approach I would take. Couldn't you simply create your own cleanup routine that you executed prior to displaying the MessageBox that closed all open files, disconnected from the database etc.?

If you are worried about the user not clicking on the message box, if you already performed your cleanup routine prior to displaying the message wouldn't that take care of that issue? It might be better to display your own window using a timeout as an alternative to a MessageBox if you are concerned with the user ignoring it.
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.