Win32 setDisplayMode api return a error

Are there any Win32 experts out there?
I don’t understand why IDirectDraw7_SetDisplayMode returns an error.

detail info: Do you know why SetDisplayMode returns an error? · Issue #35 · marlersoft/zigwin32 · GitHub
the code: demo/src/main.zig at win32-panic · jiangbo/demo · GitHub


if (failed(draw7.IDirectDraw7_SetDisplayMode( //
        WIDTH, HEIGHT, 8, 0, 0))) win32Panic();


const hr = draw7.IDirectDraw7_SetDisplayMode( //
        WIDTH, HEIGHT, 8, 0, 0); 
if (failed(hr)) {
    std.log.err("hr={x}\n", .{hr});

Possible hr values are specified in IDirectDraw7::SetDisplayMode
The value must be 0x8876#### where #### is an error code defined in ddraw.h

1 Like

I changed the code, and get a hr error code: -7fffbfff.
the code means DDERR_ALREADYINITIALIZED? What is initialized?

PS C:\workspace\demo> zig build run
info: wWinMain
info: gameInit
error: hr=-7fffbfff

error: win32 painc code 5
thread 23900 panic: ERROR_ACCESS_DENIED
C:\workspace\demo\src\main.zig:120:12: 0x3b1c87 in win32Panic (demo.exe.obj)
C:\workspace\demo\src\main.zig:99:19: 0x3b1de1 in gameInit (demo.exe.obj)
C:\workspace\demo\src\main.zig:64:13: 0x3b13d0 in wWinMain (demo.exe.obj)
C:\software\exe\zig\lib\std\start.zig:577:25: 0x3b10f2 in call_wWinMain (demo.exe.obj)
return root.wWinMain(hInstance, null, lpCmdLine, nCmdShow);
C:\software\exe\zig\lib\std\start.zig:374:53: 0x3b1013 in wWinMainCRTStartup (demo.exe.obj)
const result: = call_wWinMain();
???:?:?: 0x7ffde176257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ffde208aa57 in ??? (ntdll.dll)

-7fffbfff = 80004001 = E_NOTIMPL = DDERR_UNSUPPORTED = Action not supported.

Thanks for explaining the error code. Is this a win32 error code or a zigwin32? Hmm…it should be a win32 error.
I don’t get such errors when using cpp. source code: demo/main.cpp at win32-panic · jiangbo/demo · GitHub.

I am very confused now, not sure whether it is a problem with the zig code or my computer environment.

The cpp code ignores any errors returned from SetDisplayMode and Game_Init.

The result of using the FAILED macro is also correct. Because I want to see the return value of SetDisplayMode, I store it in r. From the debug image above, you can see that the value of r is S_OK, which means no error.

The only difference I 've seen in the code is the use of CW_USEDEFAULT instead of 0 in CreateWindowEx.

I tried running examples of zig and cpp on my computer separately, and they both returned the 80004001 error.

Should use 32-bit mode instead of 64-bit mode

If this means you are targeting x86-windows and not x86_64-windows, then be aware that Zig >= 0.13.0 currently has known miscompilations for 32-bit Windows, so that might be causing your original problem:

1 Like