DllMain

Is a prototype for startup code for a library NLM™.

Library:LibC
Classification:Windows
Service:Library

Syntax

  #include <windows.h> 
  BOOL  DllMain (
     HINSTANCE   hinstDLL,
     DWORD       fdwReason,
     LPVOID      lpvReserved);
  

Parameters

hinstDLL

(IN) Specifies the library handle when used.

fdwReason

(IN) Specifies a message or condition the library must handle. The message determines the value of the other two parameters.

lpvReserved

(IN) Specifies an NLM handle when used.

Return Values

If the message is successfully handled, it should return TRUE. Otherwise, it should return FALSE.

Remarks

DllMain is not functionality exported by LibC, but is functionality that a developer of a library writes for that library.

The DllMain prototype preserves the Win32 Hungarianisms so that if you reference the Windows standard, you will see the same identifiers. For the Microsoft document, see DllMain.

This function is called with the following messages (the fdwReason parameter) and the table explains how your library should respond to these messages and what the other parameters are set to for that message.

fdwReason Flag

hinstDll Parameter lpvReserved Parameter

Description

DLL_PROCESS_ATTACH (3)

Not used. Not used.

The library is being called as a result of a consumer's call to the dlopen function.

DLL_THREAD_ATTACH (4)

Not used. Not used.

The library is being called as a result of a call to NXThreadCreate.

DLL_THREAD_DETACH (5)

Not used. Not used.

The library is being called at the time of the thread's destruction.

DLL_PROCESS_DETACH (6)

Not used. Not used.

The library is being called as a result of a consumer's call to the dlclose function.

DLL_ACTUAL_DLLMAIN (0)

Not used. Not used.

A required nonstandard NetWare® addition that must always return TRUE. Because support for DllMain did not occur until NetWare v5.1 SP5 and NetWare v6.0 SP2, this flag lets NetWare know that DllMain is real and not a stub.

LibC exports a DllMain that returns FALSE. This interface is consumed when the loading NLM does not code a DllMain, which is the case for the majority of NLM applications.

DLL_NLM_STARTUP (1)

hinstDll contains a library handle from register_library.

lpvReserved contains the NLM handle for the library.

Nonstandard NetWare addition. DllMain is called with this flag at NLM startup. When your library receives this call, you should initialize any resources that your library needs and which haven't already been initialized with a _NonAppStart function and return TRUE.

DLL_NLM_SHUTDOWN (2)

hinstDll contains a library handle from register_library.

lpvReserved contains the NLM handle for the library.

Nonstandard NetWare addition. DllMain is called with this flag at NLM shutdown. When your library receives this call, you should clean up and free all resources and return TRUE.

See Also