Skip to main content
Question

CALL statement with Windows API crashes!

  • February 9, 2026
  • 3 replies
  • 34 views

InsyteDeveloper
Forum|alt.badge.img

The following code crashes when it is executed within Visual Studio 2022: 

CALL GetCurrentDirectory  
USING BY VALUE     PC-PATH-LENGTH
BY REFERENCE CURRENT-PC-DIRECTORY
RETURNING iRet
END-CALL.

it fails with the error message: 

173     Called program file not found in drive/directory: GetCurrentDirectoryA

I updated the PATH variable to include the folders where the COBOL runtime exists. So why does it not find the Windows API function? Is this a limitation of the PE version or some other property to build has not been set correctly? 

Any help is appreciated. 

Kevin

3 replies

Chris Glazier
Forum|alt.badge.img+3

Hi Kevin,

GetCurrentDirectory is a Windows API function, not a COBOL one. If you wish to use the COBOL equivalent take a look at CBL_GET_CURRENT_DIR

Try the following:

       identification division.
program-id. Program1.
environment division.
configuration section.
special-names.
call-convention 66 is winapi.
data division.
working-storage section.
01 PC-PATH-LENGTH pic x(4) comp-5.
01 CURRENT-PC-DIRECTORY pic x(256) value spaces.
01 iRet pic x(4) comp-5.
01 pp procedure-pointer.
procedure division.

set pp to entry "kernel32"
set PC-PATH-LENGTH to length of CURRENT-PC-DIRECTORY

call winapi "GetCurrentDirectoryA"
using by value PC-PATH-LENGTH
by reference CURRENT-PC-DIRECTORY
returning iRet
end-call
if iRet > 0
display CURRENT-PC-DIRECTORY(1:iRet)
else
display "error"
end-if

goback.

 


InsyteDeveloper
Forum|alt.badge.img
  • Author
  • Participating Frequently
  • February 10, 2026

Ok, now I see where I was missing a few pieces which caused the error condition. The recommendation to use, CBL_GET_CURRENT_DIR, is a valid one. However, in the COBOL source that would be converted, if we switch to Visual COBOL, it has far too many Windows API calls. Additionally, there is also a number of custom Windows’ DLL functions accessed, that to use the CALL ... method reduces the amount of code that would have to be refactored to match Visual COBOL’s syntax. In this instance would I change the ‘Kernel32’ reference to the actual DLL that contains our custom functions, such as, 

set pp to entry "OurCustomDll"?

I appreciate you pointing out what was lacking from my example. Thanks! 

Kevin


Chris Glazier
Forum|alt.badge.img+3

Yes, setting a procedure pointer to a .dll name that is within the PATH will load it and make its entry points available to call.