IDirect3D9 :: CreateDevice () call from DllMain hangs

What could be the reason?

From DllMain () to DLL_PROCESS_ATTACH I call IDirect3D9 :: CreateDevice () and it hangs

The code is simple, like:

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    if (ul_reason_for_call = DLL_PROCESS_ATTACH) {
        IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);

        D3DPRESENT_PARAMETERS pp = {};
        pp.BackBufferWidth = 1;
        pp.BackBufferHeight = 1;
        pp.BackBufferFormat = D3DFMT_X8R8G8B8;
        pp.BackBufferCount = 1;
        pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        pp.Windowed = TRUE;

        IDirect3DDevice9* device = NULL;
        HRESULT hr = d3d->CreateDevice(
            D3DADAPTER_DEFAULT, 
            D3DDEVTYPE_HAL, 
            GetDesktopWindow(), 
            D3DCREATE_HARDWARE_VERTEXPROCESSING, 
            &pp, 
            &device);

        device->Release();
        d3d->Release();
    }
    return TRUE;
}

GetDesktopWindow () is used for simplicity, I tried to create my own window and use it, the same result

+3
source share
1 answer

You cannot do such things in DllMain. In particular, you cannot call functions from other DLLs. This can only be done from the exported function when it is called by the main application.

Quote docs on MSDN :

DllMain , DLL .

, DLL, Kernel32.dll, , . , User, Shell COM , .

+5

Source: https://habr.com/ru/post/1775757/


All Articles