- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please advice me ..what i m dooing wrong here
the following codes are Dummy code but similar to my large application
i am using using watcomf77 compilor to make win32 dll
my appologies .. if this is not the right place to ask this question
FORTRAN 77 dll code
________________________________________________________
*$pragma aux DON "DON" export parm(value*8,value*8)
SUBROUTINE DON(DAA,DBB,DCC)
REAL*8, DAA,DBB,DCC
DBB=DAA+1
DCC=DBB+1
RETURN
END
________________________________________________________
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace pDON
{
class Program
{
[DllImport("DON.dll",
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern void DON(
[MarshalAs(UnmanagedType.R8)] double DAA,
[MarshalAs(UnmanagedType.R8)] double DBB,
[MarshalAs(UnmanagedType.R8)] double DCC
);
static void Main(string[] args)
{
//double TIME = 100.0;
double DAA = 5.5;
double DBB = 7;
double DCC = 9;
//START( ENERIN, VAL1);
DON(DAA, DBB, DCC);
Console.Write("val1 = " + DBB);
Console.Write("val2 = " + DCC);
Debug.WriteLine("VAR = " + DBB.ToString());
Console.Write("Press any key to exit");
Console.ReadKey(false);
}
}
}
________________________________________________________
I want to get the valuse of DBB DCC back to C# main prog ..after they are processed thru FORTRAN 77 subroutine
P.S. : i can not use INTENT(out) as i m using fortran 77
expected values are DBB=6.5, DCC=7.5
values i m getting DBB=7, DCC=9
Or if there is another way to get the values ..like using COMMON BLOCK .
plz show me small example
much thanks in advance
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
void routine(double *a,double *b)
Or may be problem in routine You used to print values, are correct values visible in debugger?
Jakub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
void routine(double *a,double *b)
Or may be problem in routine You used to print values, are correct values visible in debugger?
Jakub
Yes PRINT*,var is giving good result
its just ...they are not comming back to C#
i evan tryed , reference type for out put ,still same result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
*$pragma aux DON "DON" export parm(value*8,value*8)
Is not problem there?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
*$pragma aux DON "DON" export parm(value*8,value*8)
Is not problem there?
"*$pragma aux DON "DON" export parm(value*8,value*8)"
is Auxilary pragma[compilor directive]used in fortran 77 to export symbol(function or subroutine)
there is no problem in that as i m able to pass value of DAA from C# as input
and while debuggung with PRINT*,var in DLL i m getting desired values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just for information :
i am using these for compiling and linking
wmake -f C:WATCOMbinwbinDON.mk -h -e
wlink name DON d all SYS nt_dll op m op maxe=25 op q op symf @DON.lk1
wlib -q -n -b DON.lib +DON.dll
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The call from the C code must be as follow if you want to get back the changed values of DBB and DCC :
DON(DAA, &DBB, &DCC);
So, in the fortran side, you must declare that the second and the third argument of the function are pointers not values. Look the Watcom f77 documentation to change your pragma settings.
Dont forget to change the C side prototype of the function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The call from the C code must be as follow if you want to get back the changed values of DBB and DCC :
DON(DAA, &DBB, &DCC);
So, in the fortran side, you must declare that the second and the third argument of the function are pointers not values. Look the Watcom f77 documentation to change your pragma settings.
Dont forget to change the C side prototype of the function.
By Default F77 usescall-by-reference for arguments and i have alread tried call-by-value and call-by-reference at C# side
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot to everyone specially QUBA and GVAUTIER for pointing me to right direction
the input argument should be passed by value and out put arguments ...pass by refrence
so i changed my Auxilary pragma to
"*$pragma aux DON "DON" export parm(value*8, reference, reference)"
Now it works like a charm :-)
Thanks again

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page