Skip to content

Commit c520b57

Browse files
committed
Got the small example of VB calling fortran to work, checking in.
Progress for this example documented at this post: http://stackoverflow.com/questions/42749596/vb-net-calling-fortran-how-to-fix-pinvoke-exception
1 parent ea5a9c3 commit c520b57

22 files changed

+586
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = "example_fortran_directory", "example_fortran_dll\example_fortran_directory.vfproj", "{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}"
7+
EndProject
8+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Call_Fortran_example", "vb_caller\Call_Fortran_example\Call_Fortran_example.vbproj", "{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Debug|x86 = Debug|x86
14+
Release|Any CPU = Release|Any CPU
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}.Debug|Any CPU.ActiveCfg = Debug|Win32
19+
{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}.Debug|x86.ActiveCfg = Debug|Win32
20+
{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}.Debug|x86.Build.0 = Debug|Win32
21+
{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}.Release|Any CPU.ActiveCfg = Release|Win32
22+
{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}.Release|x86.ActiveCfg = Release|Win32
23+
{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}.Release|x86.Build.0 = Release|Win32
24+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Debug|x86.ActiveCfg = Debug|Any CPU
27+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Debug|x86.Build.0 = Debug|Any CPU
28+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Release|x86.ActiveCfg = Release|Any CPU
31+
{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}.Release|x86.Build.0 = Release|Any CPU
32+
EndGlobalSection
33+
GlobalSection(SolutionProperties) = preSolution
34+
HideSolutionNode = FALSE
35+
EndGlobalSection
36+
EndGlobal
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
SUBROUTINE MFNWT_RUN(KSTP,KPER,SUMMATION) !bind(C,NAME="MFNWT_RUN")
3+
!
4+
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS: 'MFNWT_RUN' :: MFNWT_RUN
5+
!DEC$ ATTRIBUTES REFERENCE :: KSTP
6+
!DEC$ ATTRIBUTES REFERENCE :: KPER
7+
!DEC$ ATTRIBUTES REFERENCE :: SUMMATION
8+
!
9+
IMPLICIT NONE
10+
! ...argument declarations
11+
INTEGER :: KPER, KSTP
12+
INTEGER :: SUMMATION
13+
14+
! *** Note to self: Don't forget about the compiler setting that appends underscore ***
15+
16+
INTEGER kkper, kkstp
17+
INTEGER add_em_up
18+
19+
kkper = KPER
20+
kkstp = KSTP
21+
22+
add_em_up = kkper + kkstp
23+
24+
SUMMATION = add_em_up
25+
26+
END SUBROUTINE MFNWT_RUN
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<VisualStudioProject ProjectType="typeDynamicLibrary" ProjectCreator="Intel Fortran" Keyword="Dll" Version="11.0" ProjectIdGuid="{9B44AEF9-294B-4CAE-B47C-61DC27A31B5D}">
3+
<Platforms>
4+
<Platform Name="Win32"/></Platforms>
5+
<Configurations>
6+
<Configuration Name="Debug|Win32" ConfigurationType="typeDynamicLibrary">
7+
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" WarnInterfaces="true" Traceback="true" BoundsCheck="true" StackFrameCheck="true" RuntimeLibrary="rtMultiThreadedDebugDLL"/>
8+
<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" GenerateDebugInformation="true" SubSystem="subSystemWindows" LinkDLL="true"/>
9+
<Tool Name="VFResourceCompilerTool"/>
10+
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
11+
<Tool Name="VFCustomBuildTool"/>
12+
<Tool Name="VFPreLinkEventTool"/>
13+
<Tool Name="VFPreBuildEventTool"/>
14+
<Tool Name="VFPostBuildEventTool" CommandLine="COPY /Y &quot;$(TargetDir)\example_fortran_directory.dll&quot; &quot;$(SolutionDir)\vb_caller\Call_Fortran_example\bin\Debug&quot;&#xA;COPY /Y &quot;$(TargetDir)\example_fortran_directory.lib&quot; &quot;$(SolutionDir)\vb_caller\Call_Fortran_example\bin\Debug&quot;&#xA;COPY /Y &quot;$(TargetDir)\example_fortran_directory.exp&quot; &quot;$(SolutionDir)\vb_caller\Call_Fortran_example\bin\Debug&quot;&#xA;COPY /Y &quot;$(TargetDir)\example_fortran_directory.pdb&quot; &quot;$(SolutionDir)\vb_caller\Call_Fortran_example\bin\Debug&quot;&#xA;COPY /Y &quot;$(TargetDir)\vc140.pdb&quot; &quot;$(SolutionDir)\vb_caller\Call_Fortran_example\bin\Debug&quot;" Description="Copy test Fortran DLL to VB directory"/>
15+
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
16+
<Configuration Name="Release|Win32" ConfigurationType="typeDynamicLibrary">
17+
<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" RuntimeLibrary="rtMultiThreadedDLL"/>
18+
<Tool Name="VFLinkerTool" SuppressStartupBanner="true" SubSystem="subSystemWindows" LinkDLL="true"/>
19+
<Tool Name="VFResourceCompilerTool"/>
20+
<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
21+
<Tool Name="VFCustomBuildTool"/>
22+
<Tool Name="VFPreLinkEventTool"/>
23+
<Tool Name="VFPreBuildEventTool"/>
24+
<Tool Name="VFPostBuildEventTool"/>
25+
<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration></Configurations>
26+
<Files>
27+
<Filter Name="Header Files" Filter="fi;fd;h;inc"/>
28+
<Filter Name="Resource Files" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"/>
29+
<Filter Name="Source Files" Filter="f90;for;f;fpp;ftn;def;odl;idl">
30+
<File RelativePath="..\vb_caller\Call_Fortran_example\bin\Debug\example_fortran_directory.lib"/>
31+
<File RelativePath=".\Something_Simple.f90"/></Filter></Files>
32+
<Globals/></VisualStudioProject>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{780F2508-61F7-4DD3-B0C7-B1D7F71BF83F}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<StartupObject>Call_Fortran_example.Module1</StartupObject>
10+
<RootNamespace>Call_Fortran_example</RootNamespace>
11+
<AssemblyName>Call_Fortran_example</AssemblyName>
12+
<FileAlignment>512</FileAlignment>
13+
<MyType>Console</MyType>
14+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<DefineDebug>true</DefineDebug>
21+
<DefineTrace>true</DefineTrace>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DocumentationFile>Call_Fortran_example.xml</DocumentationFile>
24+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
25+
<UseVSHostingProcess>false</UseVSHostingProcess>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<PlatformTarget>AnyCPU</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<DefineDebug>false</DefineDebug>
31+
<DefineTrace>true</DefineTrace>
32+
<Optimize>true</Optimize>
33+
<OutputPath>bin\Release\</OutputPath>
34+
<DocumentationFile>Call_Fortran_example.xml</DocumentationFile>
35+
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
36+
</PropertyGroup>
37+
<PropertyGroup>
38+
<OptionExplicit>On</OptionExplicit>
39+
</PropertyGroup>
40+
<PropertyGroup>
41+
<OptionCompare>Binary</OptionCompare>
42+
</PropertyGroup>
43+
<PropertyGroup>
44+
<OptionStrict>Off</OptionStrict>
45+
</PropertyGroup>
46+
<PropertyGroup>
47+
<OptionInfer>On</OptionInfer>
48+
</PropertyGroup>
49+
<ItemGroup>
50+
<Reference Include="System" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.Deployment" />
53+
<Reference Include="System.Xml" />
54+
<Reference Include="System.Core" />
55+
<Reference Include="System.Xml.Linq" />
56+
<Reference Include="System.Data.DataSetExtensions" />
57+
<Reference Include="System.Net.Http" />
58+
</ItemGroup>
59+
<ItemGroup>
60+
<Import Include="Microsoft.VisualBasic" />
61+
<Import Include="System" />
62+
<Import Include="System.Collections" />
63+
<Import Include="System.Collections.Generic" />
64+
<Import Include="System.Data" />
65+
<Import Include="System.Diagnostics" />
66+
<Import Include="System.Linq" />
67+
<Import Include="System.Xml.Linq" />
68+
<Import Include="System.Threading.Tasks" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Compile Include="Module1.vb" />
72+
<Compile Include="My Project\AssemblyInfo.vb" />
73+
<Compile Include="My Project\Application.Designer.vb">
74+
<AutoGen>True</AutoGen>
75+
<DependentUpon>Application.myapp</DependentUpon>
76+
</Compile>
77+
<Compile Include="My Project\Resources.Designer.vb">
78+
<AutoGen>True</AutoGen>
79+
<DesignTime>True</DesignTime>
80+
<DependentUpon>Resources.resx</DependentUpon>
81+
</Compile>
82+
<Compile Include="My Project\Settings.Designer.vb">
83+
<AutoGen>True</AutoGen>
84+
<DependentUpon>Settings.settings</DependentUpon>
85+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
86+
</Compile>
87+
</ItemGroup>
88+
<ItemGroup>
89+
<EmbeddedResource Include="My Project\Resources.resx">
90+
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
91+
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
92+
<CustomToolNamespace>My.Resources</CustomToolNamespace>
93+
<SubType>Designer</SubType>
94+
</EmbeddedResource>
95+
</ItemGroup>
96+
<ItemGroup>
97+
<None Include="My Project\Application.myapp">
98+
<Generator>MyApplicationCodeGenerator</Generator>
99+
<LastGenOutput>Application.Designer.vb</LastGenOutput>
100+
</None>
101+
<None Include="My Project\Settings.settings">
102+
<Generator>SettingsSingleFileGenerator</Generator>
103+
<CustomToolNamespace>My</CustomToolNamespace>
104+
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
105+
</None>
106+
<None Include="App.config" />
107+
</ItemGroup>
108+
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
109+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
110+
Other similar extension points exist, see Microsoft.Common.targets.
111+
<Target Name="BeforeBuild">
112+
</Target>
113+
<Target Name="AfterBuild">
114+
</Target>
115+
-->
116+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Imports System.Collections
2+
Imports System
3+
Imports System.Runtime.InteropServices
4+
Imports System.IO
5+
Imports System.Data
6+
7+
Module Module1
8+
9+
<DllImport("example_fortran_directory.dll", CallingConvention:=CallingConvention.Cdecl)>
10+
Public Sub MFNWT_RUN(ByRef a As Integer, ByRef b As Integer, ByRef c As Integer) 'ref bool AdvFlwRdr
11+
End Sub
12+
13+
' Private Declare Sub MFNWT_RUN Lib "example_fortran_directory.dll" Alias "MFNWT_RUN" (<[In](), Out()> ByRef A As Integer, ByRef B As Integer, ByRef C As Integer)
14+
'Private Declare Sub MFNWT_RUN Lib "example_fortran_directory.dll" Alias "MFNWT_RUN" (<[In](), Out()> ByRef A As Integer, ByRef B As Integer, ByRef C As Integer)
15+
16+
Sub Main()
17+
Dim first As Integer
18+
Dim second As Integer
19+
20+
Dim answer As Integer
21+
22+
first = 6
23+
second = 7
24+
answer = 0
25+
MFNWT_RUN(first, second, answer)
26+
27+
MsgBox(answer)
28+
29+
End Sub
30+
31+
End Module

call_fortran_from_VB/vb_caller/Call_Fortran_example/My Project/Application.Designer.vb

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3+
<MySubMain>false</MySubMain>
4+
<SingleInstance>false</SingleInstance>
5+
<ShutdownMode>0</ShutdownMode>
6+
<EnableVisualStyles>true</EnableVisualStyles>
7+
<AuthenticationMode>0</AuthenticationMode>
8+
<ApplicationType>2</ApplicationType>
9+
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
10+
</MyApplicationData>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Imports System
2+
Imports System.Reflection
3+
Imports System.Runtime.InteropServices
4+
5+
' General Information about an assembly is controlled through the following
6+
' set of attributes. Change these attribute values to modify the information
7+
' associated with an assembly.
8+
9+
' Review the values of the assembly attributes
10+
11+
<Assembly: AssemblyTitle("Call_Fortran_example")>
12+
<Assembly: AssemblyDescription("")>
13+
<Assembly: AssemblyCompany("")>
14+
<Assembly: AssemblyProduct("Call_Fortran_example")>
15+
<Assembly: AssemblyCopyright("Copyright © 2017")>
16+
<Assembly: AssemblyTrademark("")>
17+
18+
<Assembly: ComVisible(False)>
19+
20+
'The following GUID is for the ID of the typelib if this project is exposed to COM
21+
<Assembly: Guid("8f175bd0-a931-4cc3-b86b-799bad077715")>
22+
23+
' Version information for an assembly consists of the following four values:
24+
'
25+
' Major Version
26+
' Minor Version
27+
' Build Number
28+
' Revision
29+
'
30+
' You can specify all the values or you can default the Build and Revision Numbers
31+
' by using the '*' as shown below:
32+
' <Assembly: AssemblyVersion("1.0.*")>
33+
34+
<Assembly: AssemblyVersion("1.0.0.0")>
35+
<Assembly: AssemblyFileVersion("1.0.0.0")>

call_fortran_from_VB/vb_caller/Call_Fortran_example/My Project/Resources.Designer.vb

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)