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

<< < (4/5) > >>

OptimalDesigns:
The following VB code give an error when trying to execute it ... ideas where my problem is?
---
      If EndDLL("PSDcalc_for.dll") Then MsgBox "It worked!"
---
The VB debugger says 'EndDLL' expected variable or procedure, not module.  Hmm, "EndDLL" is a function as described next.
---
Public Function EndDLL(DllReturnValue As Long) As Boolean

'PURPOSE: End a process started with VB's Shell Statement
'INPUT: Task ID returned by Shell
'RETURNS: True if succesful, false otherwise

On Error Resume Next

Dim hInst As Long
Dim hProcess As Long
Dim lExitCode As Long
Dim lRet As Long

hInst = DllReturnValue
If hInst = 0 Then Exit Function

'Get handle to process
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, hInst)
If hProcess <> 0 Then
    'get exit code
    GetExitCodeProcess hProcess, lExitCode
        If lExitCode <> 0 Then
                'bye-bye
            lRet = TerminateProcess(hProcess, lExitCode)
            EndDLL = lRet > 0
        End If
End If
End Function
---

KodeZwerg, you are probably right on the problem is in my VB -exit- code ... not the DLL.   On the inet the talk is about 'Close' vs. 'Close All'.  Ideas?

wraith808:
Is your DLL stdcall?

From just that bit of code, I think it's on your VB side, as that sort of calling (using the shell statement) is not something I've seen used for DLLs.  From my experience, that's used in shelling out to an executable.

How is your declaration done?  And how is your DLL called?  That seems different from what you've posted above.

KodeZwerg:
What i see is absolutely a no-go. No wonder that Application hang if you try to kill Processes at end. A DLL aint a process.
CreateProcess() TerminateProcess() and such are made to run/kill external Applications, not DLL.

I have no time ATM, will come back later and post how to correct call a DLL with VB. (i have to search "how-to" for VB.... not my territory)

Ps: with Delphi i used stdcall convention and it worked.

wraith808:
What i see is absolutely a no-go. No wonder that Application hang if you try to kill Processes at end. A DLL aint a process.
CreateProcess() TerminateProcess() and such are made to run/kill external Applications, not DLL.

I have no time ATM, will come back later and post how to correct call a DLL with VB. (i have to search "how-to" for VB.... not my territory)

Ps: with Delphi i used stdcall convention and it worked.
-KodeZwerg (July 23, 2018, 12:29 PM)
--- End quote ---

That's not what he has in his code example is my concern.  But as for an example:

http://computer-programming-forum.com/49-fortran/eb9fb0a7df21d33e.htm

KodeZwerg:
Hello again, as more i read about VB and working with DLL as more confused i get.
Many informations lead into a direction that VB need some kind of special prepared DLL. (i think wraith808 link write something similar)
Above i think isnt needed since your App can work with Dll.

But how you work with Dll, there is something very buggy.

I've been reading on Microsofts Visual Studio Site (in German) and its so much input, you could fill books with it.
Very complicated for me to a) translate all that expert stuff to english and b) understand it by myself.
It would make no sense if i copy and paste "something" and have no clue what i pasted.
Thats far out of my scope, i am sorry!

With the programming language i use, i just type something like this, thats all i need:
function ExampleCall ( SomeParameter: ParameterType ): ResultType; stdcall; external 'Some.dll';
This would enable me to use "ExampleCall" from "Some.dll", i do not need to (un)load that dll, all happen automatic this way.

I feel sorry for not being able to help any deeper.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version