Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking VC with Fortran

Status
Not open for further replies.

ljc420

Programmer
Jun 13, 2001
9
US
I am currently working on a project that requires that I write a VC++ library that is called by a Visual FORTRAN (Compaq's) program. The resources that I have found say that it is relatively easy to do this, however they are not really specific about the details.

I have a class with about 6 functions that I want to make external. What do I need to do in order to change these functions to be able to be called from FORTRAN? I don't have to worry about the VFORTRAN code only the VC++ stuff. Also do I need to create any special kind of project (either ATL/COM or .dll)?
 
just create a statically linked library John Fill
1c.bmp


ivfmd@mail.md
 
Yes, but don't I need to write something special in the code such that the FORTRAN program can access my functions.

My current function
void Class1::foo(int x, int y, char *something)
{
}

Do I need to add anything to this or will it be able to link to this fine? Also what file would the FORTRAN program link to (.obj, .pch, .tlb)?
 
My advice is you to make your export functions as:

//foo implementing
void Class1::foo(int x, int y, char *something)
{
}
//export function for calling from fortran
void foo(void* handle, int x, int y, char *something)
{
((Class1*)x)->foo(x,y,something);
}
//use handles where is possible. John Fill
1c.bmp


ivfmd@mail.md
 
So out of curiousity will that change the way that the function is from the FORTRAN program?
 
The way that the function is CALLED. Will that change the way that the function is called from FORTRAN?

Sorry I didn't get enough sleep last night.
 
Yes, because of different kinds of coding and names conventions, calling conventions ... The most language independent is COM. So if you know COM you can make AtiveX DLL or EXE servers in ATL of MFC or make them just in ordinary DLL or EXE using COM API. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top