ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

How to close a Fortran DLL routine when exiting Visual Basic (front-end) program

<< < (5/5)

KodeZwerg:
What i suggest you should do:

Post your code where you define that dll call. (like i did in my previous post " ExampleCall () ")
Post your complete exit-routine code. <<< if i guess right, there should be the error.

That way more people can help and we do not need to guess whats wrong.

OptimalDesigns:
Yes, I forgot the declare stuff...


--- ---Private Declare Sub PSDcalc_for Lib "PSDcalc_for.dll" (ByVal fileNam As String, ByRef x_array As Single, _
  ByRef spectrum As Single, nptsZ As Integer, npointsZ As Integer, _
  t_startZ As Single, t_finalZ As Single, zeroFillZ As Single, sig2Z As Single, _
  nPoles As Integer, nZeros As Integer, M_eqs As Integer, M_lags As Integer, _
  Mode As Integer, L_pts As Integer, ByVal str_len As Long)
ooo

Public Sub exitProgram()
  ooo
' no longer have this code ...      Call EndProcess("PSDcalc_for.dll")
      If EndDLL("PSDcalc_for.dll") Then MsgBox "It worked!"

A problem is in the EndDLL("PSDcalc_for.dll") stmt.  EndDLL argument should be EndDLL(DllReturnValue As Long) ... that's a problem for sure.  What should be passed to EndDLL ... DllReturnValue As Long?

wraith808:
The parameter it's asking for is a Windows handle. 

But beyond that, there's something intrinsically wrong with this, I think.  Where did you get that EndDLL function from?  It seems to me that you're mixing ideas in calling the Fortran DLL from VB, and though you have it working, it's really not being called as intended, therefore your results could be suspect, as your problem coming out of the method point towards memory access errors.

Just ideas- I'm shooting very much in the dark here with only partial code to work from; it appears that your method, if it's defined as above, is not defined as _stdcall.  Check that first link I put in there- the instructions are for Fortran90, i.e.

If you are using CVF, then just add the following to the declaration of
mydllsub:
!DEC$ATTRIBUTES STDCALL:: mydllsub
!DEC$ATTRIBUTES DLLEXPORT:: mydllsub
!DEC$ATTRIBUTES ALIAS: 'mydllsub'::mydllsub
!DEC$ATTRIBUTES REFERENCE:: myarray,n,m

--- End quote ---

Then remove that EndDLL function and try it- that would be my final suggestion.

KodeZwerg:
Other things that i do not understand fully yet:

--- --- If EndDLL("PSDcalc_for.dll") Then MsgBox "It worked!"Translated in my world this would mean: If "something is TRUE" then "show Text"
BUT "EndDLL" is defined
--- ---Public Function EndDLL(DllReturnValue As Long) As Boolean wich contain
--- ---hInst = DllReturnValue
Heres my problem:
You call EndDLL with a "String" but EndDLL wants "Long" as input.... VB or your Text is very confusing me :)

And yeah, comment that "EndDLL" out of Exit-Code.

Navigation

[0] Message Index

[*] Previous page

Go to full version