Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dllmain in DLL library in VC++

Tags:

dll

visual-c++

I am going through my project code base, which consits of libraries and applications. Some libraries are Dll's. Code is written in C++ for Windows using MS VS 2010.

I taught for Dll we should write DllMain function which is entry point for the DLL application. But in my project for DLL "DllMain" function is not present.

My question when we require DllMain and when it is not required?

Thanks for your time and help.

like image 244
venkysmarty Avatar asked Jun 07 '12 06:06

venkysmarty


People also ask

Does a DLL need DllMain?

DllMain is not mandatory. If you have some initialization code required to run when loading the dll, you should create a DllMain function, and treat the initialization there. Otherwise it's not required. See here some more information.

What is DllMain used for?

The DllMain function is an optional method of entry into a dynamic-link library (DLL). If the function is used, it is called by the system when processes and threads are initialized and terminated, or upon calls to LoadLibrary and FreeLibrary.

How do I reference a DLL in Visual Studio C++?

In Visual C++, click the Browse tab in the Add References dialog box. Click Browse, locate the component that you want on your local drive, and then click OK. The component is added to the Selected Components field.


1 Answers

DllMain is not mandatory. If you have some initialization code required to run when loading the dll, you should create a DllMain function, and treat the initialization there. Otherwise it's not required.

See here some more information.

like image 197
Alexandru C. Avatar answered Oct 06 '22 21:10

Alexandru C.