Created On:  18 December 2012

Problem:

Customer has a C application that loads COBOL DLLs at runtime and makes calls into them.
This is working, but the application is leaking memory.
The reason for the leaks is because they are currently NOT calling the cobthreadtidy() method whenever a C created thread terminates.

However, they are unable to successfully call into cobthreadtidy() without receiving an Access Violation.
They then added a call to cobinit() to their application, but that also results in an Access Violation.

They have also written a very small console application that simply calls cobinit(), but that too throws an Access Violation!
There must be something missing here.

Here is the source code for the sample console application:

#include "stdafx.h"
#include "../Microfocus/INCLUDE/cobmain.h"
int _tmain(int argc, _TCHAR* argv[])
{
    HMODULE hModule = ::LoadLibrary(_T("CBLRTSM.dll"));
    cobinit();
    return 0;
}

They have tried with and without the LoadLibrary() call, but this seems to make no difference to the outcome.
They are linking their code to CBLRTSM.lib so shouldn’t need the LoadLibrary() call.

Their main question is : What compiler options and libraries do I need in order to call successfully into cobinit() and cobthreadtidy()?

Resolution:

There are two approaches that can be taken to calling Micro Focus runtime functions from C code:

1) link with cblrtsmi.lib, and then call the functions directly

OR

2) use LoadLibrary on the runtime, get hold of the runtime function to be called using GetProcAddress and then call the function indirectly via that function pointer

When compiling the C code, it should also be built to use the shared C runtime (/MD) as that then matches what the COBOL runtime uses.

The customer’s example is incorrect in that it is doing a mixture of both 1 and 2.

They are also linking with cblrtsm.lib rather than cblrtsmi.lib, so that most likely is what their actual problem is.