WinUser.HWND_MESSAGE is truncated to 32 bits on 64-bit JVMs (CreateWindowEx fails with ERROR_INVALID_WINDOW_HANDLE)
还没有人认领这个 Issue。
评估
调研方向
从 WinUser 中 HWND_MESSAGE 的声明开始,并比较 issue 中描述的 Pointer.createConstant 重载。检查其他负数句柄常量是否如建议所述使用 int 重载。完成标准是能够在 64 位 JVM 上创建仅接收消息的窗口,并验证受影响的常量。
由索引模型根据 Issue 内容生成。
描述
Description
WinUser.HWND_MESSAGE is declared as:
HWND HWND_MESSAGE = new HWND(Pointer.createConstant(-3));
Pointer.createConstant(int) masks the value with 0xFFFFFFFFL, so on a 64-bit JVM the handle becomes 0x00000000FFFFFFFD instead of 0xFFFFFFFFFFFFFFFD ((HWND)-3). Windows rejects it as a parent window, so a message-only window cannot be created with this constant.
Environment
- jna / jna-platform 5.19.1 (the declaration is unchanged on
master) - Windows 11 x64, 64-bit JVM (Zulu 11)
Steps to reproduce
WinUser.WNDCLASSEX wc = new WinUser.WNDCLASSEX();
wc.hInstance = Kernel32.INSTANCE.GetModuleHandle(null);
wc.lpfnWndProc = (WinUser.WindowProc) (h, msg, wp, lp) -> User32.INSTANCE.DefWindowProc(h, msg, wp, lp);
wc.lpszClassName = "HwndMessageTest";
User32.INSTANCE.RegisterClassEx(wc);
WinDef.HWND hwnd = User32.INSTANCE.CreateWindowEx(0, "HwndMessageTest", "", 0, 0, 0, 0, 0,
WinUser.HWND_MESSAGE, null, wc.hInstance, null);
System.out.println(hwnd + " error=" + Native.getLastError());
Expected
A message-only window handle is returned.
Actual
hwnd is null and Native.getLastError() returns 1400 (ERROR_INVALID_WINDOW_HANDLE).
Passing new WinDef.HWND(Pointer.createConstant(-3L)) instead works. The window is created, and WTSRegisterSessionNotification / WM_WTSSESSION_CHANGE work as expected.
Suggested fix
Use the long overload, so the value is sign-extended on 64-bit and still correct on 32-bit:
HWND HWND_MESSAGE = new HWND(Pointer.createConstant(-3L));
Other handle constants in jna-platform that are built with createConstant(int) and a negative value may have the same problem and could be checked too.
- 主要语言
- Java
- 星标
- 8.9k
- 派生
- 1.7k
- 平均合并
- 3 小时 57 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
java-native-access/jna 的其他 Issue
-
MacFileUtils: FSPathMakeRef passes an int where the C function takes its FSRef output pointer可能重新可做 @VelpulaGangavardhan 于 39 天前认领,目前没有进行中的 PR。 未关闭
难度 1/5 1 小时以内 新手友好度 79/100
java-native-access/jna#1746 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 43/100
java-native-access/jna#1752 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 44/100
java-native-access/jna#1751 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 48/100
java-native-access/jna#1747 · 1 条评论 ·
-
`Native.typeOptions` never releases library interfaces, leaking classloaders可能已有人在做 @curforever 于 51 天前认领。 未关闭
难度 4/5 1-2 天 新手友好度 48/100
java-native-access/jna#1742 ·
查看 java-native-access/jna 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
eclipse-ee4j/eclipselink#3105 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 65/100
humblemuzzu/dumbtv#250 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
NucleusFramework/Nucleus#1020 ·
维护者通常 1 天内回复