- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have written a DLL in Intel Visual Fortran that does numerous calculations. Part of the code follows below from the Fortran DLL. I then call this in Excel 2007 using the Declare Function FTOK_F Lib "C:\\xxx" (Arg as double) as double. I then write a macro in VBA:
I then use this as a function in Excel, i.e., =FtoK(50).
This works fine in Excel on my machine. When i transfer the DLL to another machine, the DLL does not work (the macro in Excel just stops and i get the #Value in the cell that calls it.
Furthermore, if i include this in a vb.net (2008) project using the exact same method as i did in VBA, i receive an exception that states: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I am confused on why the macro seems to work fine within Excel on my machine, but then does not work within vb.net. I figure once i get that working, then i will focus on the "other machine" issue.
The Fortran DLL code follows (note: there is much more to this code, but this is the specific function i tried to get to work in vb.net -- they all work in VBA):
[vb]Public Function FtoK(T As Double) As Double FtoK = FTOK_F(T) End Function [/vb]
I then use this as a function in Excel, i.e., =FtoK(50).
This works fine in Excel on my machine. When i transfer the DLL to another machine, the DLL does not work (the macro in Excel just stops and i get the #Value in the cell that calls it.
Furthermore, if i include this in a vb.net (2008) project using the exact same method as i did in VBA, i receive an exception that states: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I am confused on why the macro seems to work fine within Excel on my machine, but then does not work within vb.net. I figure once i get that working, then i will focus on the "other machine" issue.
The Fortran DLL code follows (note: there is much more to this code, but this is the specific function i tried to get to work in vb.net -- they all work in VBA):
[fxfortran] module ConversionFunctions implicit NONE CONTAINS real(8) function FtoR_fnc(Arg) !dec$ attributes dllexport :: FtoR_fnc !dec$ attributes stdcall, REFERENCE, alias :'FTOR_F' :: FtoR_fnc implicit none real(8) Arg FtoR_fnc = Arg + 459.67 return end function FtoR_fnc real(8) function RtoK_fnc(Arg) !dec$ attributes dllexport :: RtoK_fnc !dec$ attributes stdcall, REFERENCE, alias :'RTOK_F' :: RtoK_fnc implicit none real(8) Arg RtoK_fnc = (Arg)/1.8 return end function RtoK_fnc real(8) function FtoK_fnc(Arg) !dec$ attributes dllexport :: FtoK_fnc !dec$ attributes stdcall, REFERENCE, alias :'FTOK_F' :: FtoK_fnc implicit none real(8) Arg FtoK_fnc = RtoK_fnc(FtoR_fnc(Arg)) return end function FtoK_fnc END MODULE ConversionFunctions [/fxfortran]
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You may also need to install the Microsoft Visual C++ Redistributables. Or, and this may be simpler, change the Libraries > Use Run-Time Library property to "Multithreaded" (and not Multithreaded DLL). Be sure you are building a Release configuration.
I'll get the "containscontains" issue fixed.
I'll get the "containscontains" issue fixed.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When i posted this, i noticed in the fortran code that the key word CONTAINS is listed twice. I am not sure why this is the case, but it is not in the actual code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just figured out part of my problem. vb.net defaults to passing arguments ByVal. Changed the Declare statement to (ByRef Arg as double) and everything worked fine.
Still have not figured out how to transport the DLL to a different computer. I did install the Fortran redistributables to the target machine.
Help is greatly appreciated!
Still have not figured out how to transport the DLL to a different computer. I did install the Fortran redistributables to the target machine.
Help is greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You may also need to install the Microsoft Visual C++ Redistributables. Or, and this may be simpler, change the Libraries > Use Run-Time Library property to "Multithreaded" (and not Multithreaded DLL). Be sure you are building a Release configuration.
I'll get the "containscontains" issue fixed.
I'll get the "containscontains" issue fixed.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page