# Loader Lock

**what is loader lock ?**

Loader Lock is a special internal lock , windows holds while loading or unloading DLLs

So Windows restricts these operations inside **DllMain** to avoid deadlocks or hangs.

So DLL Sideloading is not possible.

Inside **DllMain**, Windows holds the **loader lock**.

`LoadLibrary()` also needs the **loader lock**.

So:

*   DllMain holds the lock
    
*   LoadLibrary waits for the lock
    
*   → **Deadlock** (process hangs)
    

That’s why **loading another DLL from DllMain is considered unsafe and effectively “not possible.”**

![](https://cdn.hashnode.com/uploads/covers/69441e0da418bf1fc22446c0/7ae5fe08-e72e-40b6-b071-971fba069bf7.png align="center")

Loading another DLL *from inside DllMain* is unsafe and usually impossible without causing deadlocks.

```cpp
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
    if (fdwReason == DLL_PROCESS_ATTACH)
    {
        LoadLibrary(L"example.dll");  // ❌ Dangerous here!
    }
    return TRUE;
}
```
