Click to See Complete Forum and Search --> : C++ calling COBOL Procedures


jtuan
April 14th, 1999, 03:24 PM
I am having problem link VC++ and COBOL. The following is the COBOL:
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. COB2.
000030 DATA DIVISION.
000040 LINKAGE SECTION.
000041 01 C-LINKAGE.
000055 05 LK-ORIGIN.
000056 10 LK-ORIGIN-G.
000057 15 LK-ORIGIN-ST PIC 9(0002).
000058 15 LK-ORIGIN-CO PIC 9(0003).
000059 15 LK-ORIGIN-CI PIC 9(0004).
000060 15 LK-ORIGIN-SUB PIC 9(0003).
000061 PROCEDURE DIVISION WITH STDCALL LINKAGE USING C-LINKAGE.

The VC++ Code:
#include <windows.h>
void JMPCINT2();
void JMPCINT3();
struct g
{
char st[2];
char co[3];
char ci[4];
char sub[3];

};
long WINAPI COB2(struct g*);
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpCmd,int nCmd)
{
struct g test;

MessageBoxEx (NULL, "Start COBOL", "CallCOB", MB_APPLMODAL, LANG_ENGLISH);
JMPCINT2();
COB2(&test);
MessageBoxEx (NULL, cString, "Check Data", MB_APPLMODAL, LANG_ENGLISH);
JMPCINT3();

MessageBoxEx (NULL, "End COBOL", "CallCOB", MB_APPLMODAL, LANG_ENGLISH);

return (0);
}

Paul McKenzie
April 14th, 1999, 05:26 PM
I have never linked COBOL with C++, but the first thing that you should check is that the members of "struct g" are aligned the same way as COBOL would expect them. Remember that VC++ by default aligns members on an even boundary. If you need to convince yourself, what is the value of "sizeof(g)? I bet it isn't 12!

You need to specify that struct g is aligned on 1 byte boundaries. You can do this by using #pragma pack, or specifiying the byte alignment in the compiler settings.

Regards,

Paul McKenzie