I want to know how to access the data in a Fortran 90 Module from Visual C++. I am using Visual C++ .net 2003 and Intel Fortran 10.1. I added the fortran .lib file to the linker inputs in visual c++. My program compiles no problem, but then has an access violation error upon running.
The values in the fortran code are always zero. I would like for the "C++ values" to used/modified by the Fortran code and then be able to used the new values in C++.
Any help is greatly appreciated.
Code:
C++ header file foo.h
#pragma pack(2)
extern "C" char name[30];
extern "C" struct{
int forTyp_mp_x,
float forTyp_mp_y,
int forTyp_mp_z,
float forTyp_mp_ARR[100][10];
}fortType;
#pragma pack()
extern "C" void USEFORTMOD();
class foo
{
test();
~test();
init();
}
C++ foo.cpp file
#include <foo.h>
void init()
{
forTyp_mp_x = 5;
forTyp_mp_y = 3.3;
...
forTyp_mp_arr2(1) = 1.5;
USEFORTMOD();
}
Fortran module file fort_mod.for
module fortmodule
character*30 name
pointer x
pointer y
pointer z
pointer arr(:,:)
pointer arr2(:)
type forTyp
integer x
real y
integer z
real arr(:,:)
real arr2(:)
end type forTyp
type(forTyp), pointer:: ptr2typ0
Fortran useFortmod.for
subroutine useFortmod()
use fortmodule;
allocatable arr2(:)
do i=1,x
z=arr2(i)+ z
write(*,*)'z= ',z
enddo
end
The values in the fortran code are always zero. I would like for the "C++ values" to used/modified by the Fortran code and then be able to used the new values in C++.
Any help is greatly appreciated.