help with cpp char* arg passed to fortran function in DLL

help with cpp char* arg passed to fortran function in DLL

In Windows 7 x64 environment. Compiled "W2_model.dll" in Visual Studio 2010 with intel Fortran compiler. "ce_qual_w2" is the "exported" function in "W2_model.dll".  My pointer character argument in cpp is getting corrupted when passed to the Fortran function.  Any help would be greatly appreciated

Problem:  At run time FNAME is corrupted in Fortran function

abbreviated snips from my cpp code:

typedef int  (*W2ADAPTER_CE_QUAL_W2) (char*);

m_hInst = ::AfxLoadLibrary("W2_model.dll");

W2ADAPTER_CE_QUAL_W2   m_ce_qual_w2Fn;

m_ce_qual_w2Fn     = (W2ADAPTER_CE_QUAL_W2)   GetProcAddress(m_hInst,"ce_qual_w2"); 

char *FNAME="test";

int var = m_ce_qual_w2Fn(FNAME);

abbreviated snips from my Fortran code

INTEGER(4) FUNCTION CE_QUAL_W2 (FNAME)

!DEC$ATTRIBUTES STDCALL      :: ce_qual_w2
!DEC$ ATTRIBUTES DLLEXPORT :: CE_QUAL_W2

 CHARACTER(4) :: FNAME

DIRC = FNAME  ( at run time FNAME = '4   '  when I expect it to be 'test')

  RETURN
END FUNCTION CE_QUAL_W2

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de mecej4

I think that you have oversimplified the problem. Your Fortran function code does not make much sense. DIRC is default-typed to REAL, the function name is never assigned to, and you assign a character string to a real variable. No Fortran compiler will produce a DLL from this source.

Please construct a complete test problem and repost.

I have solved my problem,  I was missing the following line from my Fortran code. 

 !DEC$ATTRIBUTES REFERENCE  :: FNAME

Inicie sesión para dejar un comentario.