My DLL wants to close the program in which it's running

R

Robert Rollins

Hi all,
I'm writing some additions to an existing C++ DLL, and one of the
things I need to add is a generic way to close down the program in
which my DLL is running (so I can close down whatever program may have
loaded it). Can I just call exit(0)? That seems like a really
dramatic way to go about this, and I'm thinking that it might be a bad
idea. Any advice would be greatly appreciated.
 
R

red floyd

Robert said:
Hi all,
I'm writing some additions to an existing C++ DLL, and one of the
things I need to add is a generic way to close down the program in
which my DLL is running (so I can close down whatever program may have
loaded it). Can I just call exit(0)? That seems like a really
dramatic way to go about this, and I'm thinking that it might be a bad
idea. Any advice would be greatly appreciated.

Wrong group. The C++ Standard (ISO/IEC 14882:2003) doesn't discuss
DLLs. Try a group with windows or microsoft in the name. See FAQ 5.9

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9
 
R

red floyd

BobR said:
red floyd said:
Robert said:
Hi all,
I'm writing some additions to an existing C++ DLL,
[snip]
Wrong group. The C++ Standard (ISO/IEC 14882:2003) doesn't discuss
DLLs. Try a group with windows or microsoft in the name. See FAQ 5.9

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

But Red, I thought a 'Doubly Linked List' (std::list) WAS on topic here. <G>

From the OP:
I'm writing some additions to an existing C++ DLL, and one of the
things I need to add is a generic way to close down the program in
which my DLL is running (so I can close down whatever program may have
loaded it). Can I just call exit(0)? That seems like a really
dramatic way to go about this, and I'm thinking that it might be a bad
idea. Any advice would be greatly appreciated.

Where do you see "Doubly Linked List"? How to kill a process from
within a DLL is OT.
 
R

red floyd

BobR said:
But Red, I thought a 'Doubly Linked List' (std::list) WAS on topic here. <G>

DOH!!!!! Ignore my other reply to this. I missed the "<g>" marker :-(
Good one!
 
B

BobR

red floyd said:
DOH!!!!! Ignore my other reply to this. I missed the "<g>" marker :-(
Good one!

Imagine the confusion we could create if every time some poor guy asks about
a window$ DLL in this NG, we *wedge* in a 'std::list' answer. :-}

I started to answer the OP with something like, "no, you don't need to use
exit(), just let the instantiation go out of scope.". But.....
 
J

James Kanze

I'm writing some additions to an existing C++ DLL, and one of the
things I need to add is a generic way to close down the program in
which my DLL is running (so I can close down whatever program may have
loaded it). Can I just call exit(0)? That seems like a really
dramatic way to go about this, and I'm thinking that it might be a bad
idea. Any advice would be greatly appreciated.

There are only two standard ways to normally terminate a
process: return from main, and call exit(). (There's also
abort(), but I don't think we can consider that "normally
terminating".) Generally, it's better to avoid calling exit(),
since that means that the destructors of local variables aren't
called, but unless the main routine has provided for some other
conventions, there's not much else you can do. (In a number of
my programs, I use the convention of throwing an int; main
catch'es the int, and returns the value thrown. But this only
works because main() establishes the convention.)

BTW: you can ignore the idiots complaining about off topic.
Your question is quite appropriate here. But some people just
like to hear themselves talk, and since they can't think of
anything else...
 
R

red floyd

James said:
I'm writing some additions to an existing C++ DLL, and one of the
things I need to add is a generic way to close down the program in
which my DLL is running (so I can close down whatever program may have
loaded it). Can I just call exit(0)? That seems like a really
dramatic way to go about this, and I'm thinking that it might be a bad
idea. Any advice would be greatly appreciated.

[redacted]

BTW: you can ignore the idiots complaining about off topic.
Your question is quite appropriate here. But some people just
like to hear themselves talk, and since they can't think of
anything else...

No, James, I don't believe it's appropriate. Usage of exit() is
definitely on topic. But the behavior of exit() when called from a DLL
is specifically off topic.
 
K

Kai-Uwe Bux

red said:
James said:
I'm writing some additions to an existing C++ DLL, and one of the
things I need to add is a generic way to close down the program in
which my DLL is running (so I can close down whatever program may have
loaded it). Can I just call exit(0)? That seems like a really
dramatic way to go about this, and I'm thinking that it might be a bad
idea. Any advice would be greatly appreciated.

[redacted]

BTW: you can ignore the idiots complaining about off topic.
Your question is quite appropriate here. But some people just
like to hear themselves talk, and since they can't think of
anything else...

No, James, I don't believe it's appropriate. Usage of exit() is
definitely on topic. But the behavior of exit() when called from a DLL
is specifically off topic.

I would hope that the behavior of exit() when called from within a DLL
(whatever that may be) is not any different from what the standard has to
say about the behavior of exit() when called; otherwise the implementation
would seem to be non-conforming. Therefore, I do not see, how the answer to
the question depends on the DLL-issue.

As far as I can see, the OP mentioned DLLs just to indicate that he was
prepared to hear that, from within DLLs, there are special rules. That the
standard does not provide those rules does not render the question
off-topic but just allows for a simpler answer.


Best

Kai-Uwe Bux
 
J

James Kanze

James said:
I'm writing some additions to an existing C++ DLL, and one of the
things I need to add is a generic way to close down the program in
which my DLL is running (so I can close down whatever program may have
loaded it). Can I just call exit(0)? That seems like a really
dramatic way to go about this, and I'm thinking that it might be a bad
idea. Any advice would be greatly appreciated.
[redacted]
BTW: you can ignore the idiots complaining about off topic.
Your question is quite appropriate here. But some people just
like to hear themselves talk, and since they can't think of
anything else...
No, James, I don't believe it's appropriate. Usage of exit() is
definitely on topic. But the behavior of exit() when called from a DLL
is specifically off topic.

If the behavior were platform specific, agreed. It's not.
Discussing details of a specific platform API is off topic, but
talking about generally available features, like dynamic
linking, are not off topic per se. Neither would be comparing
implementations, or discussing what will be in the next version
of the standard. Just because the symbol DLL happened to be in
the posting doesn't make it off topic.

The C++ standard actually tries to take DLL's into account, in
one place (order of initialization). I don't think it really
succeeds, and I don't think it should have, without completely
addressing the issue.

Note too that implicit dynamic linking is actually standard
conformant, today. The standard doesn't say when the final
phase of translation takes place, and as long as the the
observable behavior is conform with what is required by the
standard for the source code, an implementation can defer
linking as long as it likes.
 
R

red floyd

Kai-Uwe Bux said:
I would hope that the behavior of exit() when called from within a DLL
(whatever that may be) is not any different from what the standard has to
say about the behavior of exit() when called; otherwise the implementation
would seem to be non-conforming. Therefore, I do not see, how the answer to
the question depends on the DLL-issue.

As far as I can see, the OP mentioned DLLs just to indicate that he was
prepared to hear that, from within DLLs, there are special rules. That the
standard does not provide those rules does not render the question
off-topic but just allows for a simpler answer.

OK, I'll concede the point. Sorry if I came off as a bit of a pig.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top