Mega Search
23.2 Million


Sign Up

Make a donation  
Stopping execution of a C++ dll  
News Group: borland.public.cppbuilder.language.cpp

I am using a DLL (in C++) to handle file parsing/reading for an application 
I'm writing in Delphi.  When there's an error in the file I obviously want 
to stop parsing and tell the user, I have a function which is called which 
handles all errors, by currently writing them to a file.

The problem with that is after I write the error file, I can't figure how to 
stop the DLL from continuing to parse the file.

Here's how it works currently: When an error is encountered, I throw an 
error and catch it in the calling function and then in turn call a function 
which writes the error to a file.

Now I need to stop the parsing, so I use exit(0) in the dll, you would think 
that this should close the dll right?  Nope, it closes the entire Delphi 
program too.  Is there any way I can send a message or throw an error 
through the DLL boundary into Delphi (in a format that Delphi can actually 
read w/o turning into an EEFFACE error), and halt the dll, or simply kill it 
from memory?

- Dan


Vote for best question.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 10:46 AM EST
From: Dan
 
Re: Stopping execution of a C++ dll  
News Group: borland.public.cppbuilder.language.cpp
"Remy Lebeau (TeamB)"  wrote in message 
news:477e9c34$1@newsgroups.borland.com...
>
> "Dan"  wrote in message 
> news:477e8750$1@newsgroups.borland.com...
>
>> Ah!  I was still thinking with a Delphi mindset
>> where return doesn't immediately return.
>
> There is no 'return' command in Delphi.  Perhaps you are thinking of the 
> Result variable instead?
>
>
> Gambit

Right again.  Jumping back and forth all day between two languages tends to 
make you mix things up.

- Dan 


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 4:39 PM EST
From: Dan
 
Re: Stopping execution of a C++ dll  
News Group: borland.public.cppbuilder.language.cpp
"Dan"  wrote in message 
news:477e8750$1@newsgroups.borland.com...

> Ah!  I was still thinking with a Delphi mindset
> where return doesn't immediately return.

There is no 'return' command in Delphi.  Perhaps you are thinking of the 
Result variable instead?


Gambit 



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 12:46 PM EST
From: Remy Lebeau \(TeamB\)
 
Re: Stopping execution of a C++ dll  
News Group: borland.public.cppbuilder.language.cpp
"Remy Lebeau (TeamB)"  wrote in message 
news:477e7e08$3@newsgroups.borland.com...
>
> "Dan"  wrote in message 
> news:477e7195$1@newsgroups.borland.com...
>
>> The problem with that is after I write the error file, I can't figure
>> how to stop the DLL from continuing to parse the file.
>
> If a single function is doing all the reading/parsing, then simply exit 
> the function, preferably with an error result so the application knows the 
> function failed.
>
>> Now I need to stop the parsing, so I use exit(0) in the dll, you
>> would think that this should close the dll right?
>
> No, exit() will terminate the entire application.  In C++, 'return' is the 
> command to exit a function.
>
>> Is there any way I can send a message or throw an error through the DLL
>> boundary into Delphi (in a format that Delphi can actually read w/o
>> turning into an EEFFACE error)
>
> Not safely, no.
>
>> and halt the dll, or simply kill it from memory?
>
> That is not the way to handle this situation.
>
>
> Gambit

Ah!  I was still thinking with a Delphi mindset where return doesn't 
immediately return.  Ok, I'm now using return and it's stopping and 
returning the error just fine.

Thank you

- Dan 


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 12:21 PM EST
From: Dan
 
Re: Stopping execution of a C++ dll  
News Group: borland.public.cppbuilder.language.cpp
"Dan"  wrote in message 
news:477e7195$1@newsgroups.borland.com...
>I am using a DLL (in C++) to handle file parsing/reading for an application 
>I'm writing in Delphi.  When there's an error in the file I obviously want to 
>stop parsing and tell the user, I have a function which is called which 
>handles all errors, by currently writing them to a file.
>
> The problem with that is after I write the error file, I can't figure how to 
> stop the DLL from continuing to parse the file.
>

In addition to what the others have said, note that calling a function in a 
DLL is basically like any other call. Your calling process executes the DLL 
function and then returns. The DLL is just a library, not a separate process 
that runs by itself.

-- 
Bruce 


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 1:13 PM EST
From: Bruce Salzman
 
Re: Stopping execution of a C++ dll  
News Group: borland.public.cppbuilder.language.cpp
"Dan"  wrote in message 
news:477e7195$1@newsgroups.borland.com...

> The problem with that is after I write the error file, I can't figure
> how to stop the DLL from continuing to parse the file.

If a single function is doing all the reading/parsing, then simply exit the 
function, preferably with an error result so the application knows the 
function failed.

> Now I need to stop the parsing, so I use exit(0) in the dll, you
> would think that this should close the dll right?

No, exit() will terminate the entire application.  In C++, 'return' is the 
command to exit a function.

> Is there any way I can send a message or throw an error through the DLL
> boundary into Delphi (in a format that Delphi can actually read w/o
> turning into an EEFFACE error)

Not safely, no.

> and halt the dll, or simply kill it from memory?

That is not the way to handle this situation.


Gambit 



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 10:40 AM EST
From: Remy Lebeau \(TeamB\)
 
Re: Stopping execution of a C++ dll  
News Group: borland.public.cppbuilder.language.cpp
"Dan"  wrote:

>Here's how it works currently: When an error is encountered, I throw an 
>error and catch it in the calling function and then in turn call a function 
>which writes the error to a file.
>
>Now I need to stop the parsing, so I use exit(0) in the dll, you would think 
>that this should close the dll right?

Err, you stopped parsing when you threw the exception, didn't you.
Assuming that parsing is an iterative (and possibly recursive) process,
so long as your catch block is outside the outermost parsing loop,
you're no longer inside the loop, so you *can't* continue.

Anyway, the answer is probably very simple - just return rather than
exit(). exit() is only for use when you know that everything has gone so
catastrophically wrong that the application as a whole must stop right
away. Which is what it's doing.

Are you getting confused with the Windows Structured Execution Handling
(SEH) which does allow you to retry whatever failed?

Alan Bellingham
-- 
Team Browns
ACCU Conference 2008: 2-5 April 2008 - Oxford, UK

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 6:02 PM EST
From: Alan Bellingham