Skip to main content

We have 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 we are currently NOT calling the cobthreadtidy() method whenever a C created thread terminates. However, I am unable to successfully call into conthreadtidy() without receiving an Access Violation.  I then added a call to cobinit() to our application, but that also results in an Access Violation.

 I have also written a very small console application that simply calls cobinit(), but that too throws an Access Violation!  There must be something missing from what I’m doing. 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;

}

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

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

The Access Violation is coming from the very start of the cobinit() method.  The first few lines of disassembly are shown below:

_cobinit:

0042A760  push        ecx 

0042A761  mov         eax,dword ptr [_mFt_rt_trace_flags (489DA4h)]

0042A766  mov         dword ptr [esp],0

0042A76E  mov         ecx,dword ptr [eax]

The second instruction loads an address into the EAX register, but this address is 0x00000000.  So when the fourth instruction attempts to read the contents of that address, the Access Violation is triggered.

The address of ‘_mFt_rt_trace_flags’ appears to be unknown to the CBLRTSM.lib library.  Is there anything else that I need to do to have this value defined?

I’m using Visual Studio 2008 & Netexpress 6.1

Any help/advice would be much appreciated, Thanks a lot

We have 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 we are currently NOT calling the cobthreadtidy() method whenever a C created thread terminates. However, I am unable to successfully call into conthreadtidy() without receiving an Access Violation.  I then added a call to cobinit() to our application, but that also results in an Access Violation.

 I have also written a very small console application that simply calls cobinit(), but that too throws an Access Violation!  There must be something missing from what I’m doing. 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;

}

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

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

The Access Violation is coming from the very start of the cobinit() method.  The first few lines of disassembly are shown below:

_cobinit:

0042A760  push        ecx 

0042A761  mov         eax,dword ptr [_mFt_rt_trace_flags (489DA4h)]

0042A766  mov         dword ptr [esp],0

0042A76E  mov         ecx,dword ptr [eax]

The second instruction loads an address into the EAX register, but this address is 0x00000000.  So when the fourth instruction attempts to read the contents of that address, the Access Violation is triggered.

The address of ‘_mFt_rt_trace_flags’ appears to be unknown to the CBLRTSM.lib library.  Is there anything else that I need to do to have this value defined?

I’m using Visual Studio 2008 & Netexpress 6.1

Any help/advice would be much appreciated, Thanks a lot

The following response is from MF Development:

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

2) OR 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 I think that’s what their actual problem is.

Thanks.