- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you have a C++ main program functioncalling a Fortran DLL function?
Or a C++ DLL functioncalling a Fortran DLL function? More details please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page