How to avoid Excel to shut down if a dll crashes?

Yobanlong

New Member
Joined
Sep 18, 2008
Messages
39
I have developed a dll in Fortran, and calls it from Excel. Normally this works very good.

If the dll crashes during execution (for example due to division by zero or some other problem) also Excel crashes down, without saving.

I have tried to add On Error Goto... before the call to the dll, but it does not work, if the dll crashes, Excel crashes too.

Is there another way to "keep Excel alive" if a called dll crashes?

Thanks for an excellent forum!!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Why don't you redesign the fortran dll code and add the error handling there instead of in the excel calling code .. maybe add some checking

A dll crashing excel is sometimes due to trying to access a wrong memory .. Does your dll make use of a callback function in excel ?
 
Last edited:
Upvote 0
Error handling in Fortran is, unfortunately, not at all easy. Obviously, I have added plenty of check routines through the code to avoid most errors, but it is a very large and complex program including a lot of mathematical computations and iterations. It consist of round 100 subroutines, and adding the Fortran-error-checks (which are not as elegant as in vba) to all of them would be a huge amount of work. If you have some good tips of how error handling can be added in Fortran it would be appreciated.

I think most of the times it crashes it is due to division by zero or other "illegal" mathematical operations, for example log of negative numbers, which obviously shouldn't have been negative. It also crashes if the dll tries to write to screen or to a closed file. This never happens if calculation goes as it should, but can sometimes occur of something goes wrong.

I don't know what "callback function" is - so I guess I am not using it???? I call the dll, send some numbers in to it, and get the result back. Thats all.

The program does not crash often - and in most of the cases only for untrained users who put in "wrong" numbers.

If it had worked, it would be a very simple solution to just add "OnErrorGoto" in the vba code, but that does not work.
 
Upvote 0
Error handling in Fortran is, unfortunately, not at all easy. Obviously, I have added plenty of check routines through the code to avoid most errors, but it is a very large and complex program including a lot of mathematical computations and iterations. It consist of round 100 subroutines, and adding the Fortran-error-checks (which are not as elegant as in vba) to all of them would be a huge amount of work. If you have some good tips of how error handling can be added in Fortran it would be appreciated.

I think most of the times it crashes it is due to division by zero or other "illegal" mathematical operations, for example log of negative numbers, which obviously shouldn't have been negative. It also crashes if the dll tries to write to screen or to a closed file. This never happens if calculation goes as it should, but can sometimes occur of something goes wrong.

I don't know what "callback function" is - so I guess I am not using it???? I call the dll, send some numbers in to it, and get the result back. Thats all.

The program does not crash often - and in most of the cases only for untrained users who put in "wrong" numbers.

If it had worked, it would be a very simple solution to just add "OnErrorGoto" in the vba code, but that does not work.

I have no knowledge of Fortran but I did write some C++ dlls in the past and only experienced crashes (shuts down) when using a callback function in the vba calling code.

A callback function is basically a function residing in the dll client that the dll calls .. this is often achieved by passing the address of the vba function to the dll using the AdressOf operator so that the dll can then call the vba function using the CallWindowProc or DispCallFunc APIs .

Now if the dll tries to call the vba function and the vbditor happens to be in STOP/CREATION mode due to an unhandled vba error then you get a nice crash and have to resart excel.

However, based on my experience and unlike what you say, if the vba code properly handles the error using error checkings such as On Error Goto then no crash happens.
 
Upvote 0
That is not how a Fortran dll works.... and No, I don't have any callbacks.

The problem is actually not that the dll crashes - the problem is that it takes down Excel too.
 
Upvote 0

Forum statistics

Threads
1,215,196
Messages
6,123,578
Members
449,108
Latest member
rache47

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top