I work on a simple console application in C# 4.6.1. I can make cobol program using Micro Focus environnent. My goal is to call, from console application, cobol program which have calls to another cobol program.
Today I can call with success cobol methods in cobol dll file, using DllImport or LoadLibrary.
In my example, my cobol method named Hello, in dll file hello.dll, print "Hello :D" and in the same way, my another cobol program named Itsme, in dll file itsme.dll, print "It's me".
Inside Cobol program, we can call another program with his name. In my example, I add the the following line in my Hello program :
CALL "ITSME"
In my console application, I load both dll file (hello.dll and itsme.dll). When I call my method Hello, it's supposed to print "Hello It's me". But it won't, because of :
Load error : file 'Itsme'
error code: 173, pc=0, call=1, seg=0 173
Called program file not found in drive/directory
I know it work on Unix system, using dlopen instead of LoadLibrary. LoadLibrary isn't the equivalent of dlopen ?
EDIT : There is a little sample of code after looking to Simon Sobisch answer :
#include "stdafx.h"
#include "stdio.h"
#include "windows.h"
#include "cobtypes.h"
typedef int(__stdcall *f_cobinit)();
typedef cobrtncode_t(__stdcall *f_cobcall)(const cobchar_t *callname, int argcnt, cobchar_t **argvec);
int main()
{
HINSTANCE dll1 = LoadLibrary("CobolDlls.dll");
HINSTANCE dll2 = LoadLibrary("CobolDlls2.dll");
HINSTANCE dllCbl = LoadLibrary("cblrtsm.dll");
printf("cobinit : ");
f_cobinit init = (f_cobinit)GetProcAddress(dllCbl, "cobinit");
printf("%d", init());
f_cobcall hi = (f_cobcall)GetProcAddress(dllCbl, "cobcall");
cobrtncode_t c = hi((cobchar_t*)"P2", 0, NULL);
getchar();
}
I successfully load librairies, and my call to cobinit is working (result : 0). But when I call cobcall method, I have the error code 173 seen previously.
I precise that "P2" is refering to a cobol program named "P2" included in "CobolDlls.dll", which is build as a shared single dynmic library with MicroFocus, and all Dlls are in the same directory than the console application.
P2 program :
identification division.
program-id. P2.
data division.
working-storage section.
local-storage section.
procedure division.
display "Hello I'm P2"
goback.
Thanks for your help, Yoann
LoadLibraryfor the COBOL moules. Thecobcallis the function that has to do the call. I've adjusted my answer (even if this is more "guessing" [with only having the MF docs at hand...]) - Simon Sobisch