Hello NG,
If a particular dynamic library gets loaded, I need to ensure that a
function in that library gets executed on startup (and I want the mechanism
to use only Standard C++). Here's what I've got:
void func()
{
// This is the function that must be executed
}
struct foo
{
foo() {func();}
} global_var;
I would like to solicit suggestions on more elegant alternatives. (I
realize that elegance is subjective!)
Thank you!
Dave 11 2079
Dave wrote: If a particular dynamic library gets loaded, I need to ensure that a function in that library gets executed on startup (and I want the mechanism to use only Standard C++). Here's what I've got:
void func() { // This is the function that must be executed }
struct foo { foo() {func();} } global_var;
I would like to solicit suggestions on more elegant alternatives. (I realize that elegance is subjective!)
The more _sure_ alternative to call that function _upon_loading_ of that
dynamic library would be to call it from the dynamic library _loading_
routine, which is OS-specific.
As for elegance, your method is fine. Of course, if you could make your
function to return an int, then you could make it a bit simpler:
int func() { /* blah */ return 0; }
int global_var = func();
V
Dave wrote: Hello NG,
If a particular dynamic library gets loaded, I need to ensure that a function in that library gets executed on startup (and I want the mechanism to use only Standard C++). Here's what I've got:
void func() { // This is the function that must be executed }
struct foo { foo() {func();} } global_var;
I would like to solicit suggestions on more elegant alternatives. (I realize that elegance is subjective!)
It is worse than that (being subjective). As the standard C++ language (the
one discussed here) has nothing to say about dynamic load libraries (yet),
this is not the best place for asking this question. Or running the risk of
being politically incorrect I may say, this is not the place to ask this
question. ;-) If you need another way to do what you have asked, you will
need to ask it in a newsgroup or other forum dedicated to your
platform/compiler. Most probably there is a way to do that.
--
WW aka Attila
:::
Cole's Axiom: The sum of the intelligence on the planet is a constant. The
population is growing.
"White Wolf" <wo***@freemail.hu> wrote in message
news:cs**********@phys-news1.kolumbus.fi... Dave wrote: Hello NG,
If a particular dynamic library gets loaded, I need to ensure that a function in that library gets executed on startup (and I want the mechanism to use only Standard C++). Here's what I've got:
void func() { // This is the function that must be executed }
struct foo { foo() {func();} } global_var;
I would like to solicit suggestions on more elegant alternatives. (I realize that elegance is subjective!) It is worse than that (being subjective). As the standard C++ language
(the one discussed here) has nothing to say about dynamic load libraries (yet), this is not the best place for asking this question. Or running the risk
of being politically incorrect I may say, this is not the place to ask this question. ;-) If you need another way to do what you have asked, you will need to ask it in a newsgroup or other forum dedicated to your platform/compiler. Most probably there is a way to do that.
-- WW aka Attila ::: Cole's Axiom: The sum of the intelligence on the planet is a constant. The population is growing.
I specifically want to stay within the realm of Standard C++. I don't want
to do anything compiler-specific. I probably should not have mentioned the
words "dynamic library" since their presence naturally tends to cause people
to think I'm looking for something platform-specific even though my stated
intent was the opposite. So, let's pose the problem this way:
I need to ensure that a given function is called upon program startup before
control is transferred to main(). I would like to solicit suggestions on
ways I may accomplish this that fall strictly within the standard language.
I'm looking for creative / varied ways to accomplish this as a means of 1)
Possibly improving the code I'm maintaining; 2) Expanding my knowledge of
C++.
Thanks again,
Dave
Dave wrote: [...] I specifically want to stay within the realm of Standard C++. I don't want to do anything compiler-specific. I probably should not have mentioned the words "dynamic library" since their presence naturally tends to cause people to think I'm looking for something platform-specific even though my stated intent was the opposite.
But you'd not be getting the best advice on a platform-specific feature,
if you try to look for non-platform-specific mechanism to do something
with a platform-specific element (dynamic libraries in this case). No,
I am not encouraging you to seek platform-specific advice here. Just
trying to indicate the issues with your approach.
Don't get us wrong, please.
So, let's pose the problem this way:
I need to ensure that a given function is called upon program startup before control is transferred to main().
Just to be totally generic, loading of a dynamic library doesn't
necessarily happen before 'main' is called. See 'dlopen' or 'LoadLibrary'
or whatever it is on your platform.
And, yes, as a very beginner-level C++ test question, "how to call
a function before 'main' is given control" is something we can answer,
and, besides, you had answered it in your original post.
I would like to solicit suggestions on ways I may accomplish this that fall strictly within the standard language.
That's the problem WW was trying to indicate: there are no dlls in the
standard language. So, now you're switching from a particular problem to
a generic problem, and a solution to the latter is not necessarily
an acceptable solution to the former.
I'm looking for creative / varied ways to accomplish this as a means of 1) Possibly improving the code I'm maintaining;
Staying within confines of the standard language and library may not be
an improvement in that case. Using proper OS-specific mechanisms might.
Consider yourself warned.
2) Expanding my knowledge of C++.
That never hurts, of course.
V
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:Xd*******************@newsread1.mlpsca01.us.t o.verio.net... Dave wrote: [...] I specifically want to stay within the realm of Standard C++. I don't
want to do anything compiler-specific. I probably should not have mentioned
the words "dynamic library" since their presence naturally tends to cause
people to think I'm looking for something platform-specific even though my
stated intent was the opposite. But you'd not be getting the best advice on a platform-specific feature, if you try to look for non-platform-specific mechanism to do something with a platform-specific element (dynamic libraries in this case). No, I am not encouraging you to seek platform-specific advice here. Just trying to indicate the issues with your approach.
Don't get us wrong, please.
> So, let's pose the problem this way:
I need to ensure that a given function is called upon program startup
before control is transferred to main().
Just to be totally generic, loading of a dynamic library doesn't necessarily happen before 'main' is called. See 'dlopen' or 'LoadLibrary' or whatever it is on your platform.
And, yes, as a very beginner-level C++ test question, "how to call a function before 'main' is given control" is something we can answer, and, besides, you had answered it in your original post.
> I would like to solicit suggestions on ways I may accomplish this that fall strictly within the standard
language. That's the problem WW was trying to indicate: there are no dlls in the standard language. So, now you're switching from a particular problem to a generic problem, and a solution to the latter is not necessarily an acceptable solution to the former.
I'm looking for creative / varied ways to accomplish this as a means of
1) Possibly improving the code I'm maintaining;
Staying within confines of the standard language and library may not be an improvement in that case. Using proper OS-specific mechanisms might. Consider yourself warned.
> 2) Expanding my knowledge of C++.
That never hurts, of course.
V
Please folks, forget the dynamic libs. They don't matter. They might as
well have never existed. The program I'm maintaining already works as it
is. I don't *need* another technique. I just *want* to identify creative
ways to invoke a function upon program startup, before main() is called,
because this is 99% an academic exercise to expand knowledge. If I happen
to find a technique that I like better than what's been done, I will use it,
but it is completely beside the point. To those so inclined towards
thinking of creative ways to use the language, I am giving you a friendly
challenge to exercise your C++ muscles and dazzle the NG with your
creativity / elegance!
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:Xd*******************@newsread1.mlpsca01.us.t o.verio.net... Dave wrote: [...] I specifically want to stay within the realm of Standard C++. I don't
want to do anything compiler-specific. I probably should not have mentioned
the words "dynamic library" since their presence naturally tends to cause
people to think I'm looking for something platform-specific even though my
stated intent was the opposite. But you'd not be getting the best advice on a platform-specific feature, if you try to look for non-platform-specific mechanism to do something with a platform-specific element (dynamic libraries in this case). No, I am not encouraging you to seek platform-specific advice here. Just trying to indicate the issues with your approach.
Don't get us wrong, please.
> So, let's pose the problem this way:
I need to ensure that a given function is called upon program startup
before control is transferred to main().
Just to be totally generic, loading of a dynamic library doesn't necessarily happen before 'main' is called. See 'dlopen' or 'LoadLibrary' or whatever it is on your platform.
And, yes, as a very beginner-level C++ test question, "how to call a function before 'main' is given control" is something we can answer, and, besides, you had answered it in your original post.
> I would like to solicit suggestions on ways I may accomplish this that fall strictly within the standard
language. That's the problem WW was trying to indicate: there are no dlls in the standard language. So, now you're switching from a particular problem to a generic problem, and a solution to the latter is not necessarily an acceptable solution to the former.
I'm looking for creative / varied ways to accomplish this as a means of
1) Possibly improving the code I'm maintaining;
Staying within confines of the standard language and library may not be an improvement in that case. Using proper OS-specific mechanisms might. Consider yourself warned.
> 2) Expanding my knowledge of C++.
That never hurts, of course.
V
And by the way, thank you for the alternative you have already offered!
Dave wrote: [..] To those so inclined towards thinking of creative ways to use the language, I am giving you a friendly challenge to exercise your C++ muscles and dazzle the NG with your creativity / elegance!
Thanks, Dave. It's just what we need. I can really see now how we've
stagnated here over the years. How many readers here have written a C++
book? How many have patented a template technique? Embarrassing...
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:pK*******************@newsread1.mlpsca01.us.t o.verio.net... Dave wrote: [..] To those so inclined towards thinking of creative ways to use the language, I am giving you a
friendly challenge to exercise your C++ muscles and dazzle the NG with your creativity / elegance!
Thanks, Dave. It's just what we need. I can really see now how we've stagnated here over the years. How many readers here have written a C++ book? How many have patented a template technique? Embarrassing...
Oh for God's sake, I give up. This is clearly not the place to get an
answer to a Standard C++ question. I obviously won't be missed (nor will I
miss the sarcasm).
Dave wrote: [...] Oh for God's sake, I give up.
Come on, what is this, your first day on Usenet? Don't give up
simply because you've received a sarcastic remark in response to
your own. OTOH, who cares?... Bye!
Dave wrote:
[SNIP] I specifically want to stay within the realm of Standard C++. I don't want to do anything compiler-specific. I probably should not have mentioned the words "dynamic library" since their presence naturally tends to cause people to think I'm looking for something platform-specific even though my stated intent was the opposite. So, let's pose the problem this way:
I need to ensure that a given function is called upon program startup before control is transferred to main(). I would like to solicit suggestions on ways I may accomplish this that fall strictly within the standard language.
I'm looking for creative / varied ways to accomplish this as a means of 1) Possibly improving the code I'm maintaining; 2) Expanding my knowledge of C++.
The reason why I have told you that you are asking the question in the wrong
place is because *nothing* whatsoever guarantees that *any* advice I give
you here based on my knowledge of Standard C++ will work once you try to use
in in your dynamic load libraries. Got it? When I say Standard C++ has
nothing to say (as of today, and I would say unfortunately) about dynamic
load libraries it also means, that any Standard solution I (or anyone else)
gives you here has about the same chance to work in the presence of dynamic
loading as any non-standard one. I know it sounds like I am unreasonable,
but this is really how it is. Once you say your platform, there is more
chance to give you useful ideas. But once you did that, we are off-topic
here. :-)
--
WW aka Attila
:::
Only dead fish go with the flow.
"Dave" <be***********@yahoo.com> wrote in message
news:10*************@news.supernews.com... "Victor Bazarov" <v.********@comAcast.net> wrote in message news:pK*******************@newsread1.mlpsca01.us.t o.verio.net... Dave wrote: [..] To those so inclined towards thinking of creative ways to use the language, I am giving you a friendly challenge to exercise your C++ muscles and dazzle the NG with your creativity / elegance! Thanks, Dave. It's just what we need. I can really see now how we've stagnated here over the years. How many readers here have written a C++ book? How many have patented a template technique? Embarrassing...
Oh for God's sake, I give up. This is clearly not the place to get an answer to a Standard C++ question. I obviously won't be missed (nor will
I miss the sarcasm).
dave:
please dont let this stuff bother you - just ignore it. its somewhat common
on the newsgroups (not that that excuses it) and victor has a long history
here of the sarcasm you mention as well as being a general ass with an
arrogant know it all attitude. the c++ newsgroups are apparently his life;
what more can I say? its really kind of sad.
keep posting and learning!
best,
dan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andreas Zita |
last post by:
Hi
I'm trying to figure out why my .net app take ages to start for the first
time. Well over 10 seconds. I'm not doing anything particullary cpu intense
at startup so I'm a bit confused. I have read that it takes "a while" for
the .net framwork to load the first time but this long??
Does anyone have any suggestion that could boost the...
|
by: Beni |
last post by:
I have been programming in C for about a year now. It sounds silly,
but I never took the time to question why a C(or C++ or Java) program
execution begins only at the main(). Is it a convention or is there
some deeper underlying reason?
|
by: romixnews |
last post by:
Hi,
I'm facing the problem of analyzing a memory allocation dynamic and
object creation dynamics of a very big C++ application with a goal of
optimizing its performance and eventually also identifying memory
leaks. The application in question is the Mozilla Web Browser. I also
have had similar tasks before in the compiler construction area....
|
by: steveeisen |
last post by:
I'm a long-time VB6 programmer in a shop that is mostly moving to VB
..NET 2005. And I'm confused about coding the start of solutions for
unattended operations.
Much of what I write is old-time batch. Such programs are started from
a scheduler and run on a server, cycling through a mass of data,
without human intervention. No form should...
|
by: Selva Chinnasamy |
last post by:
Hi I have a Windows application written in VB which has many functions. In
addition it also reads a database and generates a output file.
Currently this function is called when ever user clicks the button from UI.
But I like to call the function from command line too.
app.exe database.mdb should call the function to generate the output file....
| |
by: beaver |
last post by:
Hello!
I want to detect the way of program startup/execution..
There are several possibilities:
After logon/at startup
After the user clicked at the program icon (Desktop, Quick Launch, Start Menu)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |