Calling DLL's under Windows



Users of ACUCOBOL-GT® under Windows have the ability to call routines packaged in Dynamic Link Libraries (DLL's) written in almost any language. To achieve this there are a few things you need to know.

Firstly, there are two calling 'conventions', which specify how parameters are passed to the DLL, under Windows, the C convention and the Pascal convention. You can choose which convention to use by setting the DLL-CONVENTION environment variable, remember you can use SET ENVIRONMENT to set this. If you're not sure which convention is used by a DLL just try one. If you've got it wrong you'll know pretty quickly (can you spell GPF?).

Now we need to know how to call the DLL. If the DLL has only one 'entry-point' i.e. it only has one sub-routine packaged in it, and then we can just call it by name:

   CALL "MYDLL.DLL" USING PARAM-1, PARAM-2.

The Windows runtime always looks for a file with the '.DLL' extension if it doesn't find a COBOL program with the specified name, so we could just say CALL "MYDLL". However we find it's easier to keep track of what's going on if the extension is specified in the call.

Where the DLL has more than one entry-point we just call the DLL by name to initialise it, then call the routine by name to run it. Let's imagine that 'MYDLL.DLL' contains two routines 'routine1' and 'routine2'. We want to call 'routine2', so we code:

   CALL "MYDLL.DLL".
   CALL "routine2" USING PARAM-3.

The final thing we need to know is what format the DLL expects the parameters to be in. The main thing here is whether it expects to get the parameters as values or addresses. The default for ACUCOBOL-GT® is to pass the address, also known as 'by reference'. If the DLL expects a value, then you must specify BY VALUE on the parameter. Let's imagine that we're calling 'routine1' which expects a number as its first parameter and the address of a data item as its second; C programmers will call this a 'pointer'. Since we've already called 'MYDLL.DLL' we can just go ahead and call 'routine1':

   CALL "routine1" USING BY VALUE WS-NUMBER, WS-DATA-ITEM.

And that's it! It's really straightforward and opens up many possibilities in the Windows world.

Your Session will expire in 90 minutes
Notification will be shown in:
600 seconds