<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Call C++ dll from Fortran in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778132#M26164</link>
    <description>(Your C++ shows two declarations of a function named cwrite_ but no definition (there's no function body after the cwrite_ in the cpp file, so that's just another statement that says that a function named cwrite_ exists somewhere else). So your C++ dll has no useful code - so the linker doesn't bother creating an export library.)&lt;BR /&gt;&lt;BR /&gt;(Do you really need to have the C++ code in a DLL - i.e. are the functions that are going to be in the DLL going to be shared across applications, or in the nature of a customisable plug-in or similar? I assume that you do in the following. &lt;BR /&gt;&lt;BR /&gt;Do you really want the C++ name to end in an underscore? That's how some Fortran compilers decorated the linker names for procedures etc, but relying on that/creating such names today is needlessly fragile. I assume you don't in the following.)&lt;BR /&gt;&lt;BR /&gt;Perhaps as a starting point:[cpp]// test.h
#define CALL __declspec(dllexport)
namespace testfuncs 
{
  extern "C" void CALL cwrite();
}[/cpp] &lt;BR /&gt;[cpp]// test.cpp
#include "test.h"
#include &lt;IOSTREAM&gt;

namespace testfuncs
{
  extern "C" void CALL cwrite()
  {
    // do something visible.
    std::cout &amp;lt;&amp;lt; "Hello world" &amp;lt;&amp;lt; std::endl;
  }
}
[/cpp] &lt;BR /&gt;[fortran]! fortcall.f90
PROGRAM ForCall
  IMPLICIT NONE

  INTERFACE
    SUBROUTINE write() BIND(C,NAME='cwrite')
    END SUBROUTINE write
  END INTERFACE

  CALL write
END PROGRAM ForCall[/fortran] &lt;BR /&gt;

Within the relevant project properties in Visual Studio you will need to make sure that the C++ and Fortran projects have consistent settings for the run time library (they are both multithreaded [debug] DLL) and that the DLL is "findable" by the Fortran executable (perhaps by making the output directory for the two projects the same directory).&lt;/IOSTREAM&gt;</description>
    <pubDate>Wed, 04 Apr 2012 11:17:49 GMT</pubDate>
    <dc:creator>IanH</dc:creator>
    <dc:date>2012-04-04T11:17:49Z</dc:date>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778131#M26163</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;This is my first post in this forum and I'm pretty new at this visual studio stuff, if this is the wrong forum let me know which one it should be in.&lt;/P&gt;&lt;P&gt;I am a FORTRAN user who has a need to make calls and extract data from a C++ routine. I am not familiar with C++, nor am I very familiar with mixed language programming in general. The biggest stumbling block I have is trying to get the two codes to "see" and "like" each other if you will.&lt;/P&gt;&lt;P&gt;Here is what I'm using:&lt;/P&gt;&lt;P&gt;Intel Fortran 12 Compiler&lt;/P&gt;&lt;P&gt;Microsoft Visual Studio2008&lt;/P&gt;&lt;P&gt;I'm going to start out with baby steps first. Below is a Hello World C++ program&lt;/P&gt;&lt;P&gt;&lt;/P&gt;[bash]// test.h

#define CALL __declspec(dllexport)

namespace testfuncs{

	class testfuncs extern "C" void CALL

	cwrite_ ();
}


// testfuncs.cpp

#include "test.h"
#include &lt;IOSTREAM&gt;
#include &lt;STDEXCEPT&gt;

using namespace std;
namespace testfuncs
{
extern "C" void CALL cwrite_ ();
}[/bash] &lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN style="font-size: small;"&gt;&lt;DIV id="_mcePaste"&gt;&lt;/DIV&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;This seems to build okay and it creates a DLL named Cdll.dll.&lt;/P&gt;&lt;P&gt;First Problem ... There is no *.lib&lt;/P&gt;&lt;P&gt;I simply want to call this from a simple FORTRAN routine such as&lt;/P&gt;&lt;P&gt;program Forcall&lt;BR /&gt;implicit none&lt;BR /&gt;call write&lt;BR /&gt;end program Forcall&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;/STDEXCEPT&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Wed, 04 Apr 2012 08:51:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778131#M26163</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-04T08:51:05Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778132#M26164</link>
      <description>(Your C++ shows two declarations of a function named cwrite_ but no definition (there's no function body after the cwrite_ in the cpp file, so that's just another statement that says that a function named cwrite_ exists somewhere else). So your C++ dll has no useful code - so the linker doesn't bother creating an export library.)&lt;BR /&gt;&lt;BR /&gt;(Do you really need to have the C++ code in a DLL - i.e. are the functions that are going to be in the DLL going to be shared across applications, or in the nature of a customisable plug-in or similar? I assume that you do in the following. &lt;BR /&gt;&lt;BR /&gt;Do you really want the C++ name to end in an underscore? That's how some Fortran compilers decorated the linker names for procedures etc, but relying on that/creating such names today is needlessly fragile. I assume you don't in the following.)&lt;BR /&gt;&lt;BR /&gt;Perhaps as a starting point:[cpp]// test.h
#define CALL __declspec(dllexport)
namespace testfuncs 
{
  extern "C" void CALL cwrite();
}[/cpp] &lt;BR /&gt;[cpp]// test.cpp
#include "test.h"
#include &lt;IOSTREAM&gt;

namespace testfuncs
{
  extern "C" void CALL cwrite()
  {
    // do something visible.
    std::cout &amp;lt;&amp;lt; "Hello world" &amp;lt;&amp;lt; std::endl;
  }
}
[/cpp] &lt;BR /&gt;[fortran]! fortcall.f90
PROGRAM ForCall
  IMPLICIT NONE

  INTERFACE
    SUBROUTINE write() BIND(C,NAME='cwrite')
    END SUBROUTINE write
  END INTERFACE

  CALL write
END PROGRAM ForCall[/fortran] &lt;BR /&gt;

Within the relevant project properties in Visual Studio you will need to make sure that the C++ and Fortran projects have consistent settings for the run time library (they are both multithreaded [debug] DLL) and that the DLL is "findable" by the Fortran executable (perhaps by making the output directory for the two projects the same directory).&lt;/IOSTREAM&gt;</description>
      <pubDate>Wed, 04 Apr 2012 11:17:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778132#M26164</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2012-04-04T11:17:49Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778133#M26165</link>
      <description>Thanks a lot lanH. Now it works</description>
      <pubDate>Wed, 04 Apr 2012 12:10:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778133#M26165</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-04T12:10:26Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778134#M26166</link>
      <description>Hello,&lt;DIV&gt;I now have a problem with the parameters. I can put in easily characters and change them.&lt;/DIV&gt;&lt;DIV&gt;Putting in a REAL or a INTEGER doesn't work.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Here my code:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV id="_mcePaste"&gt;[bash]// cppdjj.h
#define CALL __declspec(dllexport)
namespace testfuncs{
extern "C"  CALL void hello_world();
extern "C"  CALL void get_integer(int I);
extern "C"  CALL void get_real(float* I);
extern "C"  CALL void get_character(char* I);
}
// cppdjj.h#define CALL __declspec(dllexport)
namespace testfuncs{
extern "C"  CALL void hello_world();
extern "C"  CALL void get_integer(int I);
extern "C"  CALL void get_real(float* I);
extern "C"  CALL void get_character(char* I);}
// cppdll.cpp
#include "cppdjj.h"
#include &lt;IOSTREAM&gt;
using namespace std;
namespace testfuncs
{
	extern "C" void CALL hello_world(){
		cout &amp;lt;&amp;lt;"test"&amp;lt;&lt;ENDL&gt;&lt;/ENDL&gt;&lt;/IOSTREAM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;________________________________________&lt;/DIV&gt;&lt;DIV&gt;And here the Fortran Code:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[bash]program calldll
implicit none
integer :: a
real :: d 
character*255 :: c
INTERFACE  
   SUBROUTINE hello_world() BIND(C,NAME='hello_world')  
   END SUBROUTINE hello_world  
END INTERFACE 
INTERFACE  
   SUBROUTINE get_real(re) BIND(C,NAME='get_real')  
   REAL, INTENT(IN) :: re
   END SUBROUTINE get_real      
END INTERFACE 
INTERFACE  
   SUBROUTINE get_integer(in) BIND(C,NAME='get_integer')  
   INTEGER :: in
   END SUBROUTINE get_integer      
END INTERFACE 
INTERFACE  
   SUBROUTINE get_character(ch) BIND(C,NAME='get_character')  
   CHARACTER, INTENT(IN) :: ch
   END SUBROUTINE get_character
END INTERFACE 
a = 4
d = 1.346
c = "hurz"
 
!Calling C++ Dll
call hello_world
call get_real(d)
call get_integer(a)
call get_character(c)
end[/bash] &lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;____________________________________________________________________&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;This gives me the following output:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Input Real: 0018FE70&lt;/DIV&gt;&lt;DIV&gt;Enlarged: 0018FE74&lt;/DIV&gt;&lt;DIV&gt;Input Integer: 1637996&lt;/DIV&gt;&lt;DIV&gt;Enlarged: 1637997&lt;/DIV&gt;&lt;DIV&gt;Input Character: hurz&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Changed Character: der Wolf, der hase&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Any ideas how to handle this?&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 Apr 2012 14:05:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778134#M26166</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-04T14:05:33Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778135#M26167</link>
      <description>Your program is working well! You told the Fortran code to pass argument re of subroutine get_real by reference, and that is just what it did, passing the address of variable d by value. Then the C++ code was all ready to receive a pointer to float by value, and it printed out that value as Z'0018FE70'. It could also have printed out the value of the float pointed to by I as cout &amp;lt;&amp;lt; *I &amp;lt;&amp;lt; endl, but you chose not to do that. In C++, adding 1 to I adds 1*sizeof(*I) to the address that I represents, so after that I = Z'0018FE74'. If you wanted that to point at anything useful you should have declared d as real d(2) in the Fortran program and pased d(1) to get_real.&lt;BR /&gt;&lt;BR /&gt;Now, your C++ code for get_integer calls for an int by value dummy argument, but your Fortran interface block specifies an int by reference. Thus Fortran passed C++ the address of a by value. If you wanted it to pass a by value, you would have changed the declaration of in in the interface body for get_integer to&lt;BR /&gt;&lt;BR /&gt;INTEGER, VALUE :: in&lt;BR /&gt;&lt;BR /&gt;Then the C++ get_integer function interprets the address it got by value as in int, so it get printed out in decimal, also adding 1 to an int just adds 1, not 1*sizeof(what?).&lt;BR /&gt;&lt;BR /&gt;The character stuff is kind of strange, though. You have no guarantee that a terminating ASCII NUL will be present in the Fortran code as written. Had you said c = "hurz"//achar(0) it would have worked for sure. Also, a Fortran compiler might have chosen to make a temporary copy of c(1:1) and passed the address of that to get_character. If you don't want that to happen, declare argument ch in the interface block as&lt;BR /&gt;&lt;BR /&gt;CHARACTER, INTENT(IN) ::ch(*)&lt;BR /&gt;&lt;BR /&gt;Notice that get_character doesn't actually modify c because it just changes the argument I which is a pointer to char passed by value.</description>
      <pubDate>Wed, 04 Apr 2012 14:34:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778135#M26167</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2012-04-04T14:34:38Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778136#M26168</link>
      <description>Thanks a lot. But what if i want to put in just the value of a character?&lt;DIV&gt;&lt;SPAN style="font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-family: Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV id="_mcePaste"&gt;[bash]INTERFACE  
   SUBROUTINE func() BIND(C,NAME='func')  
   CHARACTER :: path(*)
   END SUBROUTINE func
END INTERFACE [/bash] &lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;_____________________________&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;cpp:&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;/DIV&gt;&lt;DIV id="_mcePaste"&gt;&lt;DIV id="_mcePaste"&gt;[bash]	extern "C"  dllfunc void func(char path){
	cout &amp;lt;&amp;lt;"Input Path: "&amp;lt;&lt;PATH&gt;&amp;lt;&lt;ENDL&gt;&lt;/ENDL&gt;&lt;/PATH&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;The char doesn't get to the dll. Any ideas?&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 05 Apr 2012 09:03:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778136#M26168</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-05T09:03:03Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778137#M26169</link>
      <description>This comment is based solely on inspection of the code that you showed in #4. &lt;BR /&gt;&lt;BR /&gt;The interface block shows &lt;B&gt;func&lt;/B&gt; as having no arguments, which is not consistent with the way that the function is declared in C/C++. Did you mean to write &lt;B&gt;SUBROUTINEfunc(path)BIND(C,NAME='func')&lt;/B&gt; ?&lt;BR /&gt;&lt;BR /&gt;Please show the actual code with the stated problem. Note also that C-interoperability does not cover Fortran character types of length other than 1.&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Apr 2012 12:11:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778137#M26169</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2012-04-05T12:11:47Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778138#M26170</link>
      <description>The interface block corresponding to your C++ prototype is&lt;BR /&gt;&lt;BR /&gt;[bash]INTERFACE
   SUBROUTINE func(path) BIND(C,NAME='func')
      USE ISO_C_BINDING
      IMPLICIT NONE
      CHARACTER(LEN=1,KIND=C_CHAR), VALUE :: path
   END SUBROUTINE func
END INTERFACE
[/bash]</description>
      <pubDate>Thu, 05 Apr 2012 15:17:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778138#M26170</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2012-04-05T15:17:43Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778139#M26171</link>
      <description>Hello,&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;is it possible to call a c++ function in fortran that needs a struct. Here is an example for the&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;c++ header:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[bash]#define dllfunc __declspec(dllexport)



namespace testfuncs{

	extern "C"  struct interface_dll;   

	extern "C"  dllfunc void berechnung(interface_dll a);
}[/bash] &lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;c++ code:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[bash]#include "din743.h"
#include &lt;IOSTREAM&gt;
using namespace std;



namespace testfuncs
{

//declare the interface
    extern "C" {
       
		 struct interface_dll{ 
         int i;
         float r;        
         char c;
         } ;

    }
	extern "C" void dllfunc berechnung(interface_dll a){
		cout &amp;lt;&amp;lt;"integer "&amp;lt;&lt;A.I&gt;&amp;lt;&lt;ENDL&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Now I want to call this in FORTRAN:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;here is my code:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[bash]program calldll

implicit none

structure /interface_dll/
   integer:: i
!   real:: r
!   character*255:: c
end structure 

record /interface_dll/:: interf

INTERFACE  
   SUBROUTINE berechnung(interf) BIND(C,NAME='berechnung')  
   structure /interface_dll/
   integer:: i
!   real:: r
!   character*255:: c
   end structure 
   record /interface_dll/:: interf
   END SUBROUTINE berechnung  
END INTERFACE 

interf%i= 7
interf%r = 1.2345
interf%c = "interface_test"

call berechnung(interf)

end[/bash] &lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;the output of the dll is the following:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;integer 5093696&lt;/DIV&gt;&lt;DIV&gt;real 2.124 e-12&lt;/DIV&gt;&lt;DIV&gt;character !&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;So how to put a struc into a c-dll? any ideas? thanks,&lt;/DIV&gt;&lt;DIV&gt;Markus&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/ENDL&gt;&lt;/A.I&gt;&lt;/IOSTREAM&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 16 Apr 2012 07:23:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778139#M26171</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-16T07:23:03Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778140#M26172</link>
      <description>Yes. Fortran types can also be given the BIND(C) attribute, which tells the compiler that the type needs to be laid out in memory in a manner which is compatible with C.&lt;BR /&gt;&lt;BR /&gt;(In Fortran, every type definition that does not have the BIND(C) attribute and is not a SEQUENCE type is unique - it describes a new type even if the text of two type definitions are identically the same. This is the reason for the error you observed - the interface_dll type defined on line 4 is treated as a completely separate type from the interface_dll type defined on line 15, and you attempt to pass an object of one variant in where another was expected.&lt;BR /&gt;&lt;BR /&gt;Types definitions with the BIND(C) attribute are treated as being equivalent as long as the definition of the type has the same type, order and name for all the components; the definitions have no private components and the type parameters are the same (not relevant for ifort of today). The name of the type in the definition doesn't matter. Similarly for SEQUENCE types.)&lt;BR /&gt;&lt;BR /&gt;You need to be mindful of pass by value/pass by reference issues discussed in #4 above. The following uses pass by reference - a pointer to the struct's data is passed rather than the struct's data itself. Whether that is appropriate depends on your needs.&lt;BR /&gt;&lt;BR /&gt;To save typing in two declarations of the same type I have used the fortran 2003 import statement (I could repeat the definition if I wanted to, as it has the BIND(C) attribute as discussed above, but I am lazy).&lt;BR /&gt;&lt;BR /&gt;Note that the fact that the C++ code is built into a dll is almost irrelevant here. I've rejigged your C++ a bit too.&lt;BR /&gt;&lt;BR /&gt;[cpp]// testfuncs.h
#define dllfunc __declspec(dllexport)

namespace testfuncs
{
   struct interface_dll
   {
      int i;
      float r;        
      char c;
   };
   // declare the function
   extern "C" dllfunc void berechnung(interface_dll* a);
}
[/cpp] &lt;BR /&gt;&lt;BR /&gt;[cpp]// testfuncs.cpp
// cl /EHsc /LD testfuncs.cpp
#include "testfuncs.h"
#include &lt;IOSTREAM&gt;
using namespace std;

namespace testfuncs
{
   // define the function
   extern "C" void dllfunc berechnung(interface_dll* a)
   {
      cout &amp;lt;&amp;lt; "test" &amp;lt;&amp;lt; a-&amp;gt;i &amp;lt;&amp;lt; endl;
   }
}
[/cpp] &lt;BR /&gt;[fortran]! ifort fortran.f90 testfuncs.lib
program call_dll
  use, intrinsic :: iso_c_binding, only: c_int, c_char, c_float
  implicit none

  type, bind(c) :: interface_dll
     integer(kind=c_int) :: i
     real(kind=c_float) :: r
     character(kind=c_char) :: c
  end type

  interface  
     subroutine berechnung(interf) bind(c,name='berechnung')  
       import :: interface_dll
       implicit none
       type (interface_dll) :: interf
     end subroutine berechnung  
  end interface 

  type(interface_dll):: interf
  
  interf%i=7
  call berechnung(interf)
end program call_dll
[/fortran]&lt;/IOSTREAM&gt;</description>
      <pubDate>Mon, 16 Apr 2012 12:31:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778140#M26172</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2012-04-16T12:31:13Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778141#M26173</link>
      <description>Super. Thanks a lot.&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Now the only thing that is not working is how to handle characters.&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Here my c++ code again:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Header:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[bash]#define dllfunc __declspec(dllexport)

namespace testfuncs{  

	struct interface_dll;

	extern "C"  dllfunc void berechnung(interface_dll *a);
}[/bash] cpp:&lt;/DIV&gt;&lt;DIV&gt;[cpp]#include "din743.h"
#include &lt;IOSTREAM&gt;
using namespace std;



namespace testfuncs
{

//declare the interface
 //   extern "C" {
       
		 struct interface_dll{ 
         int integer_value;
         float real_value;        
         char character_value;
		 char name;
         } ;

//    }
	extern "C" void dllfunc berechnung(interface_dll *a){
		
		cout &amp;lt;&amp;lt;"integer "&amp;lt;&lt;A-&gt;integer_value&amp;lt;&lt;ENDL&gt;real_value&amp;lt;&lt;ENDL&gt;character_value&amp;lt;&lt;ENDL&gt;name&amp;lt;&lt;ENDL&gt;real_value = a-&amp;gt;real_value+1;
		a-&amp;gt;integer_value = 9;
//        a-&amp;gt;character_value = "changed";
//        a-&amp;gt;name = "also_changed";
	}[/cpp] &lt;/ENDL&gt;&lt;/ENDL&gt;&lt;/ENDL&gt;&lt;/ENDL&gt;&lt;/A-&gt;&lt;/IOSTREAM&gt;&lt;/DIV&gt;&lt;DIV&gt;Here my fortran code:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[bash]program calldll

use, intrinsic:: iso_c_binding, only: c_int, c_char, c_float
implicit none


type interface_dll
   integer   (kind=c_int)           :: integer_value
   real      (kind=c_float)         :: real_value
   character (kind=c_char,len=255)  :: character_value, name
end type

type(interface_dll):: interf

INTERFACE  
   SUBROUTINE berechnung(interf) BIND(C,NAME='berechnung')  
   import::interface_dll
   implicit none
   type(interface_dll) ::interf
   END SUBROUTINE berechnung  
END INTERFACE 


interf%integer_value= 7
interf%real_value = 1.2345
interf%character_value = "char_value_test"
interf%name = "name_test"

call berechnung(interf)

end[/bash] &lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;What works:&lt;/DIV&gt;&lt;DIV&gt;change of values (real and integer) by c++ dll&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;What doesn't work:&lt;/DIV&gt;&lt;DIV&gt;changing and using characters. the c++ dll does only get simple chars...&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;console:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;real_value 1.2345&lt;/DIV&gt;&lt;DIV&gt;character_value c&lt;/DIV&gt;&lt;DIV&gt;name h&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;How to handle this? any ideas? thanks,&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;markus&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 16 Apr 2012 13:34:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778141#M26173</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-16T13:34:06Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778142#M26174</link>
      <description>c_char applies directly only to arrays of single characters, although it supports a degree of compatibility with Fortran character strings. You would need to append a null character //achar(0) to make it work as a string in C or C++. There are plenty of examples ready for your search engine to discover.</description>
      <pubDate>Mon, 16 Apr 2012 15:20:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778142#M26174</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2012-04-16T15:20:23Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778143#M26175</link>
      <description>&lt;P&gt;Only character variables with len=1 are allowed in a type with the bind(C) property. This means you want to change the way you define the type in Fortran. Also you will want to change the type definition in C++ because as it stands you only have room for one char each.A statement such as&lt;BR /&gt;&lt;BR /&gt;a-&amp;gt;character_value = "changed"&lt;BR /&gt;&lt;BR /&gt;makes no sense in C++ because it is trying to set a variable that can only hold a single char to a pointer value which holds 4 or 8 chars and has itself no sensible char value, or as changed to modify a pointer whose existence is really only implicit.You can use strcpy() or strstreams to do something more intuitive.Also the Fortran code gets more exciting because achar(0)-terminated arrays of length-1 character array aren't as convenient as length-255 scalars.Fortran does provide a syntax, however.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;[bash]#define dllfunc __declspec(dllexport)
namespace testfuncs
{
   struct interface_dll;
   extern "C" dllfunc void berechnung(interface_dll *a);
}
#include &lt;IOSTREAM&gt;
#include &lt;CSTRING&gt;
using namespace std;
namespace testfuncs
{
   struct interface_dll
   {
      int integer_value;
      float real_value;
      char character_value[255];
      char name[255];
   };
   extern "C" void dllfunc berechnung(interface_dll *a)
   {
      cout &amp;lt;&amp;lt; "integer " &amp;lt;&amp;lt; a-&amp;gt;integer_value &amp;lt;&amp;lt; endl;
      cout &amp;lt;&amp;lt; "real " &amp;lt;&amp;lt; a-&amp;gt;real_value &amp;lt;&amp;lt; endl;
      cout &amp;lt;&amp;lt; "character " &amp;lt;&amp;lt; a-&amp;gt;character_value &amp;lt;&amp;lt; endl;
      cout &amp;lt;&amp;lt; "character " &amp;lt;&amp;lt; a-&amp;gt;name &amp;lt;&amp;lt; endl;
      a-&amp;gt;real_value = a-&amp;gt;real_value+1;
      a-&amp;gt;integer_value = 9;
      strcpy(a-&amp;gt;character_value,"changed");
      strcpy(a-&amp;gt;name,"also_changed");
   }
}
[/bash]&lt;BR /&gt;[bash]program calldll
   use, intrinsic :: iso_c_binding
   implicit none
   type, bind(C) :: interface_dll
      integer(kind=c_int) integer_value
      real(kind=c_float) real_value
      character(len=1,kind=c_char) character_value(255)
      character(len=1,kind=c_char) name(255)
   end type interface_dll
   type(interface_dll) interf
   interface
      subroutine berechnung(interf) bind(C,name='berechnung')
         import
         implicit none
         type(interface_dll) interf
      end subroutine berechnung
   end interface
   interf%integer_value = 7
   interf%real_value = 1.2345
   interf%character_value = &amp;amp;
      transfer([character(size(interf%character_value)):: &amp;amp;
      "char_value_test"//achar(0)],interf%character_value)
   interf%name = &amp;amp;
      transfer([character(size(interf%name)):: &amp;amp;
      "char_value_test"//achar(0)],interf%name)
   call berechnung(interf)
   write(*,'(a,i0)') 'interf%integer_value = ',interf%integer_value
   write(*,'(a,f0.4)') 'interf%real_value = ',interf%real_value
   write(*,'(256a)') 'interf%character_value = ', &amp;amp;
      interf%character_value(1: &amp;amp;
      index(transfer(interf%character_value, &amp;amp;
      repeat('A',size(interf%character_value))),achar(0)))
   write(*,'(256a)') 'interf%name = ', &amp;amp;
      interf%name(1: &amp;amp;
      index(transfer(interf%name, &amp;amp;
      repeat('A',size(interf%name))),achar(0)))
end program calldll
[/bash]&lt;BR /&gt;[bash]integer 7
real 1.2345
character char_value_test
character char_value_test
interf%integer_value = 9
interf%real_value = 2.2345
interf%character_value = changed
interf%name = also_changed[/bash]&lt;/CSTRING&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Mon, 16 Apr 2012 22:50:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778143#M26175</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2012-04-16T22:50:20Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778144#M26176</link>
      <description>Thanks. That would work. But is there no way to get a string like 'test' into the dll and change it to 'changed' in the dll by defining another type of character?</description>
      <pubDate>Tue, 17 Apr 2012 08:15:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778144#M26176</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-17T08:15:29Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778145#M26177</link>
      <description>thanks a lot. that really helped me</description>
      <pubDate>Tue, 17 Apr 2012 11:04:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778145#M26177</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-04-17T11:04:53Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778146#M26178</link>
      <description>Hello. I've a problem calling a dll-function that is written in cpp from my fortran project.&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Unfortunately, I'm not able to receive the sources of the cpp-project. But here is what I have:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[cpp]namespace XYZ{  

 

  struct F_interface{                     // declare the FVA-interface

    int int_value;

    float real_value;        

    char text_value[80];

    char name[32];

    } ;

      

  extern "C"  dllfunc int calc_XYZ(F_interface in[100]);

}
[/cpp] &lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;dllfunc is defined in the header:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;#define dllfunc __declspec(dllexport)&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Here is how I want to call the function calc_XYZ from my fortran project:&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;[fortran]subroutine calldll

use, intrinsic:: iso_c_binding , only: c_int, c_char, c_float

implicit none

integer ::    error, i


type F_interface
   character  :: name*32, text_value*80
   integer   (kind=c_int):: int_value
   real      (kind=c_float):: real_value
end type



type(F_interface) :: fv_interf(100)



INTERFACE  
   integer function dllfunc(fv_interf) BIND(C,NAME='calc_XYZ')  
      import::FVA_interface
      implicit none
      type(F_interface) ::fv_interf(100)
   end function dllfunc  
END INTERFACE 


do i=1, 100
   call INTERF_INIT(fv_interf(i))
enddo

error = 1


error = dllfunc(fv_interf)

end[/fortran] &lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;The .lib is added. The dll is in the right folder. But I get the error:&lt;/DIV&gt;&lt;DIV&gt;LNK2019: unresolved symbol _calc_XYZ in _CALLDLL&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Any ideas how to handle that?&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Mon, 30 Jul 2012 09:43:13 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778146#M26178</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-07-30T09:43:13Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778147#M26179</link>
      <description>I do not see, for the C++ project, however, a __declspec(dllexport) for dllfunc. Before someone jumps in and says you're missing a !DEC$ ATTRIBUTES DLLIMPORT on the Fortran side, that is optional for procedures. Are you sure that dllfunc is exported?</description>
      <pubDate>Mon, 30 Jul 2012 13:55:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778147#M26179</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-07-30T13:55:27Z</dc:date>
    </item>
    <item>
      <title>Call C++ dll from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778148#M26180</link>
      <description>Thanks for your answer Steve. I've checked the dll with a tool and found out, that the name of the exported func wasn't correct. Now it works.&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Greets,&lt;/DIV&gt;&lt;DIV&gt;Markus&lt;/DIV&gt;</description>
      <pubDate>Mon, 30 Jul 2012 14:27:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778148#M26180</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-07-30T14:27:47Z</dc:date>
    </item>
    <item>
      <title>Hello, i have a problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778149#M26181</link>
      <description>Hello, i have a problem calling a c++ dll from fortran. The argument is an array of a type (fva_interface) ... here is what i have:


Header in c++:

// testfunc.h

#define dllfunc __declspec(dllexport)

namespace testfuncs{  

	struct FVA_interface;

	extern "C"  dllfunc int testfunc(FVA_interface a[100]);
}

testfunc.cpp:

// testfunc.cpp
#include "testfunc.h"
#include &lt;IOSTREAM&gt;
using namespace std;

namespace testfuncs
{

//declare the interface
       
		 struct FVA_interface{ 
                 int int_value;
                 float real_value;        
		 char text_value[80];
		 char name[32];
         } ;
	
		 
		 extern "C"  int dllfunc  testfunc(FVA_interface  a[100]){

		//test input
		cout &amp;lt;&amp;lt;"integer_value "&amp;lt;&lt;A&gt;=' ';};
		strcpy(a[0].text_value,"changed"); 
		//character: name
		for(int i=0;i&lt;SIZEOF&gt;=' ';};
   		strcpy(a[0].name,"also_changed");

		return 13;
	}
}




Here the Fortran-Code:

      PROGRAM CALL_TESTFUNC

      !DEC$ ATTRIBUTES DLLIMPORT

      USE, INTRINSIC:: ISO_C_BINDING , ONLY: C_INT, C_CHAR, C_FLOAT

      TYPE FVA_INTERFACE
        CHARACTER                :: NAME*32,   TEXT_VALUE*80
        INTEGER   (KIND=C_INT)   :: INT_VALUE
        REAL      (KIND=C_FLOAT) :: REAL_VALUE
      END TYPE

      IMPLICIT NONE

      INTEGER ::    ERROR, I 

      TYPE(FVA_INTERFACE) :: FVA_INTERF(100)

      INTERFACE  
         INTEGER FUNCTION TESTFUNC(FVA_INTERF) BIND(C,NAME='testfunc')
            IMPORT::FVA_INTERFACE
            IMPLICIT NONE
            TYPE(FVA_INTERFACE) ::FVA_INTERF(100)
         END FUNCTION TESTFUNC  
      END INTERFACE 
      
      INTERF[1]%NAME = 'TEST'
      INTERF[1]%REAL_VALUE = 1.123
      INTERF[1]%INT_VALUE = 7
      INTERF[1]%TEXT_VALUE = 'TEST TEXT VALUE'
      
      ERROR = 0

      ERROR = DIN743(FVA_INTERF)
      
      ERROR = TESTFUNC(FVA_INTERF)


      END


So: The c++ dll writes the first element of the array into the dosbox. ... only the Variable NAME gets into the dll ...

dosbox:

name
integer_value 1321549684635
real_value 1.468163514
text_value     TEST TEXT VALUE


I don't see what I'm doing wrong ... any ideas?&lt;/SIZEOF&gt;&lt;/A&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Wed, 26 Sep 2012 08:03:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778149#M26181</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-09-26T08:03:36Z</dc:date>
    </item>
    <item>
      <title>here again the testfunc.cpp</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778150#M26182</link>
      <description>here again the testfunc.cpp


#include "testfunc.h"
#include &lt;IOSTREAM&gt;
using namespace std;

namespace testfuncs
{

//declare the interface
       
struct FVA_interface{ 
int int_value;
float real_value;        
char text_value[80];
char name[32];
} ;
	
		 
extern "C"  int dllfunc  testfunc(FVA_interface  a[100]){

//test input
cout &amp;lt;&amp;lt;"integer_value "&amp;lt;&lt;A&gt;&lt;/A&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Wed, 26 Sep 2012 08:08:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Call-C-dll-from-Fortran/m-p/778150#M26182</guid>
      <dc:creator>markusda</dc:creator>
      <dc:date>2012-09-26T08:08:45Z</dc:date>
    </item>
  </channel>
</rss>

