DllMain not needed

Guys just a quick note: DllMain is an optional proc. If your dll doesn't need to do anything on process/thread attach/detach you aren't required to export it. [strike]The Windows loader checks if its been exported, and if not doesn't call it.[/strike]MSVC will generate it for you.

Edit:
MSDN seems to be giving conflicting advice:

http://msdn.microsoft.com/en-us/l...esktop/ms682583%28v=vs.85%29.aspx

indicates its an optional entry point, while the link @Siegward posted says its generated for you which suggests that its needed.

Edited by Dejan on
Yes, I think we can get rid of it now. I was just not sure why CL was refusing to make a DLL so I tried adding it, but it was actually just because (unbeknownst to me) you can't just tell the linker to do it, if you invoke via cl, you need to use the /LD switch. Last time I made a DLL, I was still doing separate compile and link lines, so I guess I never actually tried to make a DLL directly from CL before tonight!

- Casey
Great show today. I was laughing. I never thought about it. That you could do it that way. Thanks for a great time. And you didn't even need a IDLLWriterFactoryInterface even. Don't let MS see this, because if they think it will be a trend, we will have the IDirectDLL7 library faster than you can say ICoreDLLfuckup.
It's definitely one of those things where, before you think of it, you never thought of it, and then after you think of it, you wonder how you never thought of it before :)

Tomorrow should be more of the same!

- Casey
The relevant article on MSDN:
http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=VS.100%29.aspx

It states that /LD passes the /DLL flag to the linker. If no
DllMain is found, a stub that just returns TRUE is inserted for you.
Siegward
The relevant article on MSDN:
http://msdn.microsoft.com/en-us/library/2kzt1wy3%28v=VS.100%29.aspx

It states that /LD passes the /DLL flag to the linker. If no
DllMain is found, a stub that just returns TRUE is inserted for you.


That's good info.

I dislike when compilers write code behind your back, its supposed to be convenient, but can be confusing. (see c++ ctor/dtor compiler generated default rules).
There is one good reason to have DllMain even if you don't want to put any code there. If you are creating and destroying a lot of threads, Windows will call DllMain for each thread when it is created or destroyed. Even if you don't provide DllMain the C runtime does, so for every thread it initializes some stuff. Which is an overhead if you don't care about C runtime.

So to disable Window calling DllMain for each thread you need to call DisableThreadLibraryCalls function. Typically you will want to do that if dwReason is DLL_PROCESS_ATTACH. This will potentially save some performance and reduce memory usage.

I guess this is not very relevant to Handmade Hero, beause I doubt it will be creating and destroying a lot of threads at runtime. Maybe some threads, but not a lot.