问题描述
我正在尝试通过Win32 API获取显示信息。到目前为止,我已经很好地管理了EnumdisplayDevicesA,但是EnumdisplaySettingsA给我带来了麻烦。
无论我如何设置前两个变量,该函数都将返回零(指示失败),并且没有关于为什么失败的更多信息。
TypeError: func.apply is not a function
HTMLUnkNownElement.callCallback
C:/asdasd/node_modules/react-dom/cjs/react-dom.development.js:188
185 | window.event = windowEvent;
186 | }
187 |
> 188 | func.apply(context,funcArgs);
| ^ 189 | didError = false;
190 | } // Create a global error event handler. We use this to capture the value
191 | // that was thrown. It's possible that this error handler will fire more
我的来源:
- https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaysettingsw
- https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-devmodea
- https://github.com/JamesHovious/w32/blob/74b38b9b07b520e0f84a5eec5daada6c7b6a2471/typedef.go#L363
- https://docs.rs/winapi/0.2.0/i686-pc-windows-msvc/winapi/constant.ENUM_CURRENT_SETTINGS.html
解决方法
此处的代码存在多个问题。
首先,您对devMode的类型定义是针对DEVMODEW的,但您正在调用EnumDisplaySettingsA。但是,您不应该首先调用它(它是ANSI版本),所以请改用EnumDisplaySettingsW(UNICODE)。
接下来,EnumDisplaySettingsA / EnumDisplaySettingsW的第二个参数是DWORD(uint32),但是,您没有传递值,而是将地址传递给了它。
所以替换
var iModeNum uint32 = 4294967295
enumCurrentSettings := uintptr(unsafe.Pointer(&iModeNum))
只要
iModeNum := uintptr(4294967295)
它应该都可以正常工作。