Tech Support > Microsoft Windows > Development Resources > DllMain
DllMain
Posted by Kalle Rutanen on December 15th, 2003


Hi

(I'm using Visual Studio .NET 2003 and C++)

I have a problem with the DllMain, as the program doesn't seem to call it at
all.
I declare it in a dll as stated in MSDN documentation:

BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID
lpReserved)

I use load-time linking, but it doesn't work on run-time linking either.
The declaration is not in any namespace.
I haven't specified an entry point in the project settings.


Posted by Kalle Rutanen on December 15th, 2003


Okay, now I'm out...
I tried to get that DllMain work all yesterday. My mission was to open a
file in the process attachment. It didn't open it at all. Now just after I
wrote the message and tried it again, it works just fine. And I changed
nothing...


Posted by Boris Dynin on December 16th, 2003


"Kalle Rutanen" <loopkaba@nospam.mbnet.fi> wrote in message
news:brk7ci$pj5$1@phys-news1.kolumbus.fi...
won't be called.
The easiest way to see if DllMain() was called is to use OutputDebugString()
API like this:

BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID
lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
OutputDebugString("DllMain called: process attach");
break;
....
}
}

To view output generated by OutputDebugString() you could use DebugView
utility from www.sysinternals.com. Also, if you run your program under
debugger, OutputDebugString() output will appear in IDE output window.

Boris



Posted by Kalle Rutanen on December 16th, 2003


I tried this and found out that if I do not have any references to that DLL,
then it won't be loaded at all. That is, when I included a header file,
which contained a class header to a class in the DLL, then it loaded it.



Posted by Boris Dynin on December 16th, 2003


"Kalle Rutanen" <loopkaba@nospam.mbnet.fi> wrote in message
news:brn068$4f5$1@phys-news1.kolumbus.fi...
linker will omit that DLL and at run-time it won't be loaded. In order to
inspect which DLLs your program links with and which objects (in each DLL)
it uses you could try DEPENDS.EXE. Unfortunately, DEPENDS.EXE doesn't ship
with VS2003. However, it's included with Platform SDK (which is free
download at MS site). Here's where DEPENDS.EXE is located on my system:
C:\Program Files\Microsoft SDK\Bin\Depends.exe .

Boris



Posted by Kalle Rutanen on December 16th, 2003


Thank you for your answers.



Posted by Skywing on December 19th, 2003


Depends is available for free here:

http://www.dependencywalker.com

"Boris Dynin" <spam@noplease.com> wrote in message
news:biIDb.3039$XF6.70342@typhoon.sonic.net...



Similar Posts