1

I develop a website with Visual Studio 2010. I want to run a Fortran DLL. I used Intel Visual Fortran to create a .dll and to test how to use it. My code is:

      SUBROUTINE SIMPSON (N,H,I)

     !DEC$ ATTRIBUTES DLLEXPORT, DECORATE, ALIAS : "SIMPSON" :: SIMPSON
     !DEC$ ATTRIBUTES REFERENCE::N
     !DEC$ ATTRIBUTES REFERENCE::H
     !DEC$ ATTRIBUTES REFERENCE::I
      INTEGER N,H,I

      I=N+H

      RETURN
      END

which practically takes two integers, adds them and return the result. Now I have the .dll I don't know how to run it with Visual Studio. Can anyone who knows please give me steps to follow?

davidism
  • 121,510
  • 29
  • 395
  • 339
Nick
  • 13
  • 1
  • 3

3 Answers3

2

I do this all the time. What I do, is in the calling project (C#, VB.NET) I add the .dll output to the project as an existing item, with Add as Link option. Then I set it to copy if newer in the project tree.

Add Item

Add As Link

Copy If Newer

In the end it follows the binary when you compile it into the bin/Debug or bin/Release folders.

With C# you then use the [DllImport()] attrbiute like this:

[DllImport("trex_pc.dll")]
static extern Simpson(ref int N, ref int H, ref int I);

For more details look at this answer from me.

Community
  • 1
  • 1
John Alexiou
  • 28,472
  • 11
  • 77
  • 133
  • When i use it for a web application it works fine,but when i use it for a website it says that dll was not found.any idea why? – Nick Jul 25 '12 at 20:28
  • Does the `.dll` copy when you publish the website? I really do not know at all how web development handles binaries. – John Alexiou Jul 29 '12 at 02:54
  • No,it did not.I added a link with the folder that contains the .dll.Thank you for your answer – Nick Aug 01 '12 at 09:58
0

You could simply create a Console project in IVF and link in your DLL. That may require producing a .lib file containing references to your DLL. I'm not 100% sure how to do that, although perhaps it was automatically created for you.

After the library is linked in, you can simply call simpson and it should work.

bdforbes
  • 1,486
  • 1
  • 13
  • 31
0

You can use the Post-Build Event in the dll Property Pages:

  • Click right on DLL-project in Solution Explorer
  • goto Build Events - post-Build Events
  • Command Line copy/y "$(OutDir)\$(ProjectName).dll" "$(SolutionDir)\bin\debug\" The DLL will be copied each time you build the DLL or Solution. The target location might be different.
MB-F
  • 22,770
  • 4
  • 61
  • 116