Re: C coding guidelines




"Richard Heathfield" <rjh@xxxxxxxxxxxxxxx> wrote in message
news:ApadnXRMouHPxT7XnZ2dnUVZ8lCdnZ2d@xxxxxxxxx
In <M5Fom.136778$8B7.117159@xxxxxxxxxxxx>, Tech07 wrote:

Bart wrote:
On Sep 2, 2:11 am, "Tech07" <tec...@xxxxxxxxxx> wrote:
Bart wrote:
On Sep 1, 3:55 am, "Tech07" <tec...@xxxxxxxxxx> wrote:
"Richard Heathfield" <r...@xxxxxxxxxxxxxxx> wrote in message
news:5p6dnXc7LPIv5wHXnZ2dnUVZ8qGdnZ2d@xxxxxxxxx

I just created a DLL to test your theory. It has no
_DLLMainCRTStartup. It does have a lot of extraneous junk, but
that isn't one of it, so to speak.

"Extra! Extra! Read all about
it!":http://msdn.microsoft.com/en-us/library/988ye33t.aspx

Would _you_ expect such code that calls your DLL to be in the
DLL? Surely it
gets linked to the calling executable via the provided system
libraries.- Hide quoted text -

This seems to be about link-loaders specific to the C language.
They can do what they like regarding the entry points they need
to initialise the CRT, and I would expect they are all a little
different.

The link you provided was concerned with the C++ language, and
presumably MS's version of it.

Well of course, the other poster was talking about Win32
programming. Windows is largely C (probably entirely). You don't
see any classes in the
Win32 API do you? Well, sure, now that there is C++ the startup
code has to
address those requirements, but like I already noted, if you're
just doing
C, the task of replacing the startup code (if you have such a
bent) is a bit
easier.

I would find it easier to replace the lot and just be responsible
for everything. That's what I did years ago, until I started to
make use of first Win16, then Win32 + CRT.



I don't know what your point is in that passage, but I assure you
that on
Windows, with the MS linker it's simple a switch (as in "light
switch") to
send all startup code related to C library initialization to la la
land. So
not complicated at all.

I'll take your word for it.

Now if you want to REPLACE that code, that gets a
bit more involved. I'll probably be building my code that way some
day,
today though, I don't have all the info of what the startup code
does: only
the basics. I think startup code should be provided in source code
form.
Separate the proprietary OS code from the general language code.

That's the idea.

(Have to
stop here on that, or I'll start cursing the money-mongers).

So I doubt DLLMainCRTStartup would be an entrypoint meaningful to
Windows,

Well maybe then you should go talk to Bill Gates and tell him to
REMOVE it!
You go man!

From where?

From the startup code! It's either in a DLL (if you only linked with
the import libraries) or linked to your executable if you statically
linked to the runtime libraries.



it sounds like something created by your specific C
implementation.

Did you even go to the MSDN link I posted and read what was there?
Apparently not.

"...included in the C/C++ library code ... is the entry point
_DllMainCRTStartup..."

Sounds like if I wrote a DLL in assembler or my own private
language, the entry point wouldn't exist. Only the more general
DllMain might be recognised.

What do you think calls DLLMain?

Who cares? The entry point is the point where control flow enters the
code. For a loop, that's normally the beginning of the loop (but it's
possible to mung this with goto). For a function, it's the beginning
of the function (hence the withdrawal of the 'entry' keyword which,
once upon a time, was going to allow a function to have multiple
entry points). For a suite of functions such as a library or a
program, it's the set of functions that are externally visible (i.e.
non-static) in the former case, and the function that is called by
the startup code in the latter.

<snip>

What do you think calls DLLMain?

Irrelevant. My DLLs don't even /have/ a DLLMain function,

Every DLL has a DLLMain function. It is automagically provided for you if
you don't write a specific one.

so what
makes you think it necessarily has anything to do with the entry
point into DLLs?

The REAL entry point function calls a function that calls DLLMain.


.



Relevant Pages

  • Re: C coding guidelines
    ... the task of replacing the startup code ... Separate the proprietary OS code from the general language code. ... Sounds like if I wrote a DLL in assembler or my own private language, ... What do you think calls DLLMain? ...
    (comp.lang.c)
  • Re: System-wide hooking, VB+ASM
    ... >returned by the SetWindowsHookEx function used to set the hook. ... The reason is that only the /first/ instance of the DLL ... >Look up DllMain in the SDK documentation. ... standard entry point. ...
    (microsoft.public.vb.winapi)
  • Re: C coding guidelines
    ... They can do what they like regarding the entry points they need ... send all startup code related to C library initialization to la la ... It's either in a DLL (if you only linked with ... What do you think calls DLLMain? ...
    (comp.lang.c)
  • Re: C coding guidelines
    ... ALL dlls will be called BY THE LOADER before the program starts. ... This call will be done to a special entry point called DllMain ... For instance, in the dll you sent me, the header ...
    (comp.lang.c)
  • Re: C coding guidelines
    ... A DLL can contain many functions. ... This is NOT a call y your user code, it is a call by the ... This call will be done to a special entry point called DllMain ...
    (comp.lang.c)