- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have solved my problem, I was missing the following line from my Fortran code.
!DEC$ATTRIBUTES REFERENCE :: FNAME

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