문제

What can be a reason?

From DllMain() on DLL_PROCESS_ATTACH I'm calling IDirect3D9::CreateDevice() and it hangs

code is straightforward, just 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 own window and use it, the same result

도움이 되었습니까?

해결책

You cannot do these kind of things in DllMain. Specifically, you cannot call functions from other DLLs. You can only do this from an exported function, when it is called by the main application.

Quoting the docs on MSDN:

Threads in DllMain hold the loader lock so no additional DLLs can be dynamically loaded or initialized.

Calling functions that require DLLs other than Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions load other system components.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top