Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29389 Discussions

Passing strings between Intel Fortran 8.1 DLL and Visual C++

blacula
Beginner
711 Views
Cananyone explain me how to pass string from Intel Fortran 8.1 DLL to Visual C++ and vice-versa? If you can give me any example on this subject I would be most grateful.
0 Kudos
3 Replies
anthonyrichards
New Contributor III
711 Views

Do you have a C++ main program functioncalling a Fortran DLL function?

Or a C++ DLL functioncalling a Fortran DLL function? More details please.

0 Kudos
blacula
Beginner
711 Views
I have Visual C++ main program function calling a Fortran DLL subroutine and I must pass strings of variable length from Visual C++ to a Fortran DLL subroutine and strings of variable length from Intel Fortran 8.1 DLL subroutine to Visual C++ main program function. Thank you for answer.
0 Kudos
anthonyrichards
New Contributor III
711 Views

I hope the following will help you with your enquiry.

I attach a C++ main program (hello.cpp + stdafx.cpp and stdafx.h) which calls a C++ function 'Displaymessage'with two string objectarguments and two length arguments and whichpassses character strings and length arguments toan equivalent Fortran function (FORTDISPLAYMESSAGE) which is the only entry in a Fortran DLL. I use Compaq Visual Fortran and include the workspace in the Zip file. The Fortran is in the file 'STRINGS.F90' so you can create your own IVF solution.

When the Fortran DLL is created (I started with the debug version, with 'Debug single threaded DLL' specified under
the Project Settings...Fortran..Libraries tab), it produces the 'STRING.DLL' and its export/import library 'STRING.LIB'.

The import library 'STRING.LIB' must then be added to your C++ project/solution along with the C++ files included in the zip file andthe C++must be compiled in 'debug' configuration with matching debug librariesif the Fortran wasbuilt as a debug configuration. That is, both C++ and Fortran projects must agree inconfiguration and matching libraries (I think!). When compiled, the C++ project will create the executable 'hello.exe'. The 'STRING.DLL' file must be copied to the folder where the C++ .EXE file is created so that it can be found when the C++ program is executed.

When the C++ program is run, it outputs to a console window whereas I haveallowed the Fortran function to issue Message boxes, both displayed in the attached screenshot.pdf, to show that the character strings were successfully passed to and from the Fortran DLL.

I hope this helps.

0 Kudos
Reply