Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Pass values from cobol to c
Hi, we are trying to use a C++ dll from cobol, when we use a numeric
values works fine by value and by reference, but when we use string
values there's a problem, by value work fine but by reference not, when
c change the value cobol takes trash.

Cobol Program:

$set SourceFormat"Free"
$set case
identification division.

program-id. cobcallc.
data division.
working-storage section.

01 Rodri1         pic x(10).

procedure division.
set pptr to entry "ddlcplus.dll".
if pptr not =3D null
move z"1234567890"     to Rodri1
display "Alfa"
stop " "
call "Alfa" using by reference Rodri1
display "Cobol Show: " Rodri1
display "Hit Enter to end..."
stop " "
else
display "failed to load ddlcplus.dll"
end-if.
stop run.

Function in C:
__declspec(dllexport) void Alfa(char *d[])
{
*d =3D "Funciono";
printf ("C Show: %s \n", *d);
}

In then console when we run cobol progrma, we see this:

Alfa

C Show:: Funciono
Cobol Show: =CE=A6=C3=BB=E2=96=BA567890
Hit Enter to end...

Some one have and idea or an example of the problem.

Thanks
Rodrigo


Report this thread to moderator Post Follow-up to this message
Old Post
rodrigotraverso@gmail.com
03-15-06 11:55 PM


Re: Pass values from cobol to c
rodrigotraverso@gmail.com wrote:
> Hi, we are trying to use a C++ dll from cobol, when we use a numeric
> values works fine by value and by reference, but when we use string
> values there's a problem, by value work fine but by reference not, when
> c change the value cobol takes trash. <snip>

For starters, have you looked at COBOL calling C and vice versa, using
the N/E 4.0 examples :-

[url]http://supportline.microfocus.com/examplesandutilities/nesamp.asp#MixedLanguage[/u
rl]

If that doesn't give you what you want, sign up for the free Micro Focus
Forum at microfocus.com, where you can then post messages under Net Express.

Jimmy

Report this thread to moderator Post Follow-up to this message
Old Post
James J. Gavan
03-15-06 11:55 PM


Re: Pass values from cobol to c
<rodrigotraverso@gmail.com> wrote in message
news:1142443774.909734.125290@i40g2000cwc.googlegroups.com...
>Hi, we are trying to use a C++ dll from cobol, when we use a numeric
>values works fine by value and by reference, but when we use string
>values there's a problem, by value work fine but by reference not, when
>c change the value cobol takes trash.

It is probably not "trash", more likely it is the address
of "Funciono".

>Cobol Program:
>
>      $set SourceFormat"Free"
>      $set case
> identification division.
>
> program-id. cobcallc.
> data division.
> working-storage section.
>
> 01 Rodri1         pic x(10).

This should be "pic x(11)", to hold the nul character terminator.

> procedure division.
>    set pptr to entry "ddlcplus.dll".
>    if pptr not = null
>       move z"1234567890"     to Rodri1

This move is 11 characters, not the 10 it appears to be.

>       display "Alfa"
>       stop " "
>       call "Alfa" using by reference Rodri1
>       display "Cobol Show: " Rodri1
>       display "Hit Enter to end..."
>       stop " "
>     else
>        display "failed to load ddlcplus.dll"
>     end-if.
>     stop run.
>
>Function in C:
>__declspec(dllexport) void Alfa(char *d[])

"(char *d[])" is a pointer to an array of pointers to char.
Use "(char *d)", instead.

>{
>*d = "Funciono";

This assigns the address of "Funciono" to d.
Use "strcpy(d,"Funciono");" instead.

>printf ("C Show: %s \n", *d);

Use "d" without the indirection operator, "*".

>}
>
>In then console when we run cobol progrma, we see this:
>
>Alfa
>
>C Show:: Funciono
>Cobol Show: ?û?567890

The strange characters in the first four positions are
probably the address of "Funciono".

>Hit Enter to end...
>
>Some one have and idea or an example of the problem.
>
>Thanks
>Rodrigo

I think this is as close as I can be without actually testing.




Report this thread to moderator Post Follow-up to this message
Old Post
Rick Smith
03-15-06 11:55 PM


Re: Pass values from cobol to c
Years ago I used Microfocus cobol and called a C routine.  I had to
delimit the strings with a low-value.  C strings sometimes continue
until a low value or \0 in escape sequence is found.

01 MY-STRING.
05 FILLER PIC X(10) VALUE "MYSTRING".
05 FILLER PIC X(01) VALUE LOW-VALUES.
call "_cjunk' using my-string.

If you leave off the low-values (binary zeroes) the c runtime won't
know where the C string ends.  I remember having to use nstrcpy to
handle strings that didn't have low-values...
Chris.


Report this thread to moderator Post Follow-up to this message
Old Post
hcmason@sbcglobal.net
03-16-06 02:55 AM


Re: Pass values from cobol to c
hcmason@sbcglobal.net wrote:
> Years ago I used Microfocus cobol and called a C routine.  I had to
> delimit the strings with a low-value.  C strings sometimes continue
> until a low value or \0 in escape sequence is found.
>
> 01 MY-STRING.
>    05 FILLER PIC X(10) VALUE "MYSTRING".
>    05 FILLER PIC X(01) VALUE LOW-VALUES.
> call "_cjunk' using my-string.
>
> If you leave off the low-values (binary zeroes) the c runtime won't
> know where the C string ends.  I remember having to use nstrcpy to
> handle strings that didn't have low-values...
> Chris.
>
I don't know C languages at all but with reference to M/F currently he
can have following which are also used within COBOL  :-

------------------------------------------------------------------------
Nonnumeric literals can be assigned hexadecimal values by expressing the
literals as: X"nn", where each n is a hexadecimal digit , and nn can be
repeated up to 160 times.The number of hexadecimal digits can be odd.
For example, the following two lines are permitted and are equivalent:

01 an-item PIC X
MOVE X"04" to an-item
MOVE X"4" to an-item

A null-terminated string can be created by specifying Z"string" and can
be used anywhere a nonnumeric literal is permitted. The resultant
literal is equivalent to concatenating X"00" (a null byte) to the end of
the specified string. In other words, the two following lines are
equivalent:

MOVE Z"my-literal" TO an-item
MOVE "my-literal" & X"00" TO an-item

** My Note - both the above examples assume that 01 an-Item is at least
11 characters; any more characters, just chops them off with the x'00'.
**

In the following example, the PICTURE declaration has an extra byte for
the zero-byte:

01 my-name	PIC X(5) VALUE Z"Jane".
-----------------------------------------------------------------------

I just took a quick look at the M/F zipfile I've already referred him
to. The two COBOL programs I viewed were using :-

SPECIAL-NAMES.
Call Convention ??

So he may/or may not need that feature.

Jimmy

Report this thread to moderator Post Follow-up to this message
Old Post
James J. Gavan
03-16-06 02:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Cobol archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:57 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.