CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    C++ calling COBOL Procedures

    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);
    }



  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C++ calling COBOL Procedures

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured