Unable to accomplish this without getting runtime errors
Have tried creating the DLL's using the g95 compiler and need to see if
the problem is on the g95 side or the VBNet side.
Can the g95 compiler create a windows VB.net compatible DLL and if so
can anyone please send me a typical command sequence, a sample snippet,
or point me to some tech literature.
Any help is appreciated as VB.Net is pathetic when it comes to math
operations and fortran is the only way to go. A typical problem I run
takes less than a minute under Fortran and almost two hours under
''compiled" basic.
Thanks
Mike C.
Yes. See the examples below. This is adapted from a set of programs
that I wrote for VB or VBA. It has a form with 3 text boxes and 1
command button. Pressing the button puts the difference between the two
(integer) numbers in the first two boxes into the third box.
To work with VB/VBA you need to use the MinGW version of G95. I do not
know if this applies to .NET but I have stuck with MinGW instead of
Cygwin.
I created a form using vb.net 2005 express which has some differences
from VB/VBA:
controls must be on a panel
integer is 32 bits (not long)
ByVal is default (not ByRef)
TextBoxN.text (not TextN.text)
requires dot net framework 2.0
Here is the VB side:
module declaration:
Declare Function isub2 Lib "test.dll" (ByRef i As Integer, ByRef j As
Integer) As Integer
event procedure:
TextBox3.Text = Str(isub2(Val(TextBox1.Text), Val(TextBox2.Text)))
Here is the g95 side:
use MinGW version of g95 (I used the experimental 4.1)
test.f95:
function isub2(i,j)
isub2=i-j
end
test.def:
EXPORTS isub2=isub2_
make.bat:
g95 -s -shared -mrtd -o test.dll test.def test.f95
-mrtd sets the calling convention to stdcall. I have not read the docs
in detail for VB.NET but dlls created for VB/VBA generally work with
.NET. Note that passing strings and probably arrays or array slices may
be a different story. I do know that you can pass reals as well as
integers. Name mangling is different if you use modules or module
procedures.
Note that you are also limited under VB/VBA in what you can call in the
Fortran Run time library. Console I/O causes the program to quit early
but file I/O is fine. I don't know about .NET but I suppose it is the
same.
-- elliot
Thanks for the help
Dis everything as you outlined and checked the DLL with Microsoft
Depends - the Export data, ordinal etc all checked out OK.
However, when running as soon as the call occurs I get an "Unable to
load DLL filename" exception
Something must be wrong on the VB side so I tried referencing it within
Vb but can't as it is not a valid net or COM object.
Tried copying the DLL to the system and root paths along with the
project path - still no good.
Any idea on how to get net to recognize it?? What did you do in VB
6(?) to "register" the dll ??
Thanks
Mike C.
I can not remember where I put the DLL as part of a project. When I
built an .EXE I put the DLL in the same folder as the .EXE and it
worked there. That's all I had to do. Try that first.
-- elliot
Thanks, figured out the problem. Trial and error. Finally determined
that when working within the NET IDE development environment the dll
had to be placed in the bin folder - not the project folder where
everything else is. Typical of Microsoft.
Your instructions worked great - thanks so much. Was able to link about
20 fortran subs into one dll.
I also figured out how to pass a 2D arrays from VB.Net to FORTRAN and
return the results. What a difference. The math test running under VB
took in some cases 2+hours. The same test case I just ran using the
Fortran dll called from basic took less than 30 seconds and gave me the
right results.
Thanks again.
Mike C.
Sorry to not answer sooner. Out of town for a while
I have the same problem trying to work with strings.I've been able to
deal with arrays, int, dbls, and characters but not strings so far.
Will let you know if I can find a way
Mike C.
John