"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.

  • 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?
  • 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

  • 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.