how to export array in dll (to C++ program)

how to export array in dll (to C++ program)

I have written a fortran dll to manipulated some data which are stored in allocated array, and I want to put this array into C++ program. But my dll can't do it. I don't understand
fortran program:

	!M = 10, N = 20
        !DEC$ ATTRIBUTES C, DLLEXPORT :: GetArray
	INTEGER FUNCTION GetArray(Arr, MN) 
	!MS$  ATTRIBUTES REFERENCE :: Arr

	REAL Arr((M+1)*(N+1))
        INTENT(OUT) ::  Arr
	DO J = 0, N
		Do I = 0, M
			MN = MN + 1
			Arr(MN) = I*J
		END DO
	END DO
	GetArray = 0
	RETURN
	END

C++ programm:

     ......
     typedef int __stdcall (*FGetArray)(float*, int);
     .......
  float GetGrid(int *cGrid)
  {
   FGetArray intGetArray;
   float *Arr;

        LoadLibrary ...// it's ok
        GetProcAddress ... //it's ok
        ofstream in("c:\testC1.txt",ios::app);
        Arr = new float[1154];
	a = intGetArray(Arr);
        in<<"
a: "<

All trable in transfer of a array. How to do it?
2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I don't see what's wrong? The code looks fine except that there's MN missing from the actual call -- a typo? (This shouldn't compile). Ahh, yes -- it should be int* MN in declaration -- otherwise, MN can't get out of the dll.

Btw, why is GetArray a function that always returns 0? Why not a subroutine?

Jugoslav

Jugoslav
www.xeffort.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today