I am trying to create a direct 3D 9 device. I am setting everything up with this piece of code:
LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = getGameHWND();
LPDIRECT3DDEVICE9 device;
HRESULT res;
res = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, getGameHWND(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
if (res != D3D_OK) {
char buff[100];
sprintf_s(buff, 100, "%X", res);
MessageBoxA(0, "ERROR", buff, 0);
sprintf_s(buff, 100, "%X", getGameHWND());
MessageBoxA(0, "ERROR", buff, 0);
return;
}
But this function fails everytime I execute it. As a response I get the error code 0x80070057, which is according to Google E_INVALIDARG. But which argument is wrong here? I followed a tutorial, which has the exact same code as I do.
I also checked if getGameHWND() returns 0, which is not the case.
Here is my updated code:
LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (pD3D == NULL) {
MessageBoxA(0, "ERROR", "pD3D", 0);
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = getGameHWND();
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.EnableAutoDepthStencil = 0;
d3dpp.BackBufferWidth = 0;
d3dpp.BackBufferHeight = 0;
d3dpp.FullScreen_RefreshRateInHz = 0;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
LPDIRECT3DDEVICE9 device;
HRESULT res;
res = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, getGameHWND(), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
if (res != D3D_OK) {
res = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, getGameHWND(), D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &device);
}
if (res != D3D_OK) {
res = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, getGameHWND(), D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
}
if (res != D3D_OK) {
char buff[100];
sprintf_s(buff, 100, "%X", res);
MessageBoxA(0, "ERROR", buff, 0);
sprintf_s(buff, 100, "%d", getPID());
MessageBoxA(0, "ERROR", buff, 0);
return;
}
But I still get the same error message