Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Stop execution DLL

juergel
Beginner
1,034 Views
Hi,
I have a problem duringfinishing a DLL. When I finish the DLL by calling 'STOP' in the DLL, the main-program closes too without any warning.
The Background:
I wrote the main program part for calculation in Fortran (CVF 6.6) and compiles this as a DLL. The 'user-surface' or the Window-surface is written in Delphi (BD 5).
I have call-back-functions for interactions Fortran <-> Delphi. Oneof this call-backs is to stop the calculations (this are simulations) and to give the possibilityfor a graphical output (written in Delphi). - I do this by setting an integer value in the call-back-functionregulated in a 'Delphi-Button-Click'-function.
How can I finish a DLL (and only the calculation in a DLL) in the same behaviour as when I go to the 'last-line' of the DLL-code?
or
The 'STOP'-call is in many different subprograms in the DLL .
Is in Fortran the possibility to jumptothe 'last-line-of-the-progam' from any position in the code?
Thanks and regards
Ute
0 Kudos
9 Replies
Intel_C_Intel
Employee
1,034 Views
I had the same problem many years ago. I have many statistical and data management routines called from a main "monitor" program. It's a complex stat package (MicrOsiris). Any of the routines may need to abort from within common subroutines and get back many levels to the main routine. The only way I found to make it work was to write a MASM routine with two entries: 1) STOP0 and 2) STOP16. After housekeepingat the start, the main program calls STOP0, before the menu routines start. STOP0 saves all registers and stores the current address. I replace all STOP calls with a call to STOP16 which restores the registers and returns as if from STOP0.
I'd prefer a fortran solution, but this at least has worked for over ten years.....
0 Kudos
durisinm
Novice
1,034 Views

As I understand it, you cannot have a STOP statement in a DLL routine. The behavior described is what one would expect if there is one.

Your choices are to eliminate the STOP statements or to resort to assembly workarounds such as the one nvaneck described.

Mike D.

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,034 Views

This has been discussed here. If you search the Forum for "STOP Dll" you will find two longish (and interesting) threads...

Jugoslav

0 Kudos
juergel
Beginner
1,034 Views

Hi,

many thanks for help. But it isn't a solution for me. :-((

I tried the solution 'Use of divide by zero'. I got an error-message. OK, I can call the dll again or make something else. But I don't want to get an Error-Message. - I got an Error-message before too,removing the DLL-handle in the call-back-function.It was the same effect.

For the other solution

'call RaiseException(EXCEPTION_NONCONTINUABLE_EXCEPTION, 0, 0, 0)'

I am notfamiliar enought with DVF, to find the right unitfor this function. I found nothing about this in the help-file.

The first solution fromnvaneck sounds very good, but I never wrote something in MASM.

I hoped 'STOP' using in a DLL finished _only_ the DLL. - This is wrong.

You see, I have still this problem

but many thanks again for your help

Best regards

Ute


0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,034 Views
No, you can't just "jump out" from a dll. What you can do is to raise an exception and let the caller catch it in a try...catch block from a language which supports Structured Exception Handling (SEH) -- did you mention Delphi? That is supposed to leave the stack in non-damaged state (but I wouldn't place too much money on it).
Basically, both divide by zero and RaiseException are means to raise an exception (although floating-point exceptions such as the former can get tricky because the x86 processor can be set upto a mode that it doesn't raise them -- at least I think so). If you want to use RaiseException, you have to USE DFWIN (or USE KERNEL32) in the routine that calls it.
Since you mentioned DVF, I assume you mean Digital Visual Fortran 5.0 -- if I recall correctly, you have to select a "Custom" installation and check "SDK Help" or "Win32 API Help" to get Windows API help files installed. (You can add iteven now).
Also, you can download last free upgrade to 5.0 here. (Not that it matters in this particular case, but I find 5.0D far more stable than the original release).
Jugoslav
0 Kudos
sabalan
New Contributor I
1,034 Views

Ute, I am a little confused when I read your first question and then the whole discussion. Why don't you use RETURN instead of STOP?

Sabalan.

0 Kudos
juergel
Beginner
1,034 Views

Hi Sabalan,

at first, I'm enthusiastic! It's running as I want; without Error-Message. I overlooked to suppress the Error-Message with a 'try-except-end'- construction in Delphi. I use now the 'RaiseException'-function in the dll and the dll-call is embeded in a 'try-exception-end'-construction in Delphi. Many thanks to all helpers!!

The answer to your question is: the (old-)STOP-calls (Plural!) were 'deep' in the program and at different positions. I had to jump through a lot of functions and subprogramsto reachthe last RETURN or to the normal 'finishing' of the dll; they are e.g. in an iteration-function or in the solver of a differential equation. I wanted to stop from outside of the dll. On the window-surface is a Stop-button and in the dll are a lot of enquiries : "is the stop-button pressed?" . During runing the (simulation-)program you see, if the program is hanging and you can so (and now) stop it.That's all

Again, many thanks :smileyvery-happy:

Ute


0 Kudos
billaustralia
Beginner
1,034 Views
I had this problem years ago with Lahey Fortran. My main is vb6 or vba and integer div by zero works for both with the err parameter in vb set to integer divide by zero. But of course I catch that; no problem.
I am not familiar with Delphi, so I suggest you do what I did to find the div by zero solution. I set up a small code with a main in nonFortran that called sub a ina Fortran dll which called sub b. In sub b I put every method of stopping that I could think off including STOP, Call exit, div by zero of various kinds, writing to a non existant file etc.. A few produced the effect I wanted namely return to vb, but integer div by zero was the easiest to use.
To differentiate between a 'normal' end (which in the exe was a stop), an abnormal (code crash by say unplanned div by zero), and an error return (which in the exe was a STOP 7), I have an errf argument that is set to 99 immediately on entry. Both Stop and Stop 7 have been replaced by int div by zero, but before stop errf=0 and before stop 7 errf=7.
All works like a charm in Lahey, CVF and IVF.
0 Kudos
danhoyt
Beginner
1,034 Views
Bill, you said the divide-by-zero technique works for you in IVF? I used your technique (literally, I=0, I=1/I) in a CFV/C++ project that I just migrated to IVF 8.1 and theDBZ exception is no longer being thrown.
The last entry (ref: 47792) in the Fortran SW defects doc, ftp://download.intel.com/support/performancetools/fortran/fortran_swdefects.pdf, says that no warning occurs on aDBZ constant. I tried changing the I=1/I line to a calculated value (I=1/(IERROR-IERROR)), but still no exception. How did you generate your DBZ?
0 Kudos
Reply