Skip to content

Fix crash on ×32 devices #3581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Fix crash on ×32 devices #3581

wants to merge 1 commit into from

Conversation

Jack251970
Copy link
Contributor

CsWin32 doesn't generate GetWindowLong on other than x86 and vice versa. So we should use DllImport instead of CSWin32

For more info, visit microsoft/CsWin32#882.

@prlabeler prlabeler bot added the bug Something isn't working label May 24, 2025
@Jack251970 Jack251970 requested a review from jjw24 May 24, 2025 05:11
@Jack251970 Jack251970 requested a review from Copilot May 24, 2025 05:11
@Jack251970 Jack251970 added Dev branch only An issue or fix for the Dev branch build and removed bug Something isn't working labels May 24, 2025
@Jack251970 Jack251970 added this to the 1.20.0 milestone May 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a crash on ×32 devices by switching from CsWin32–generated methods to DllImport calls for window style functions. Key changes include updating method signatures and calls to use pointer-sized types, modifying the PInvoke wrappers to support both 32-bit and 64-bit architectures, and updating documentation in NativeMethods.txt to reflect the change.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Flow.Launcher.Infrastructure/Win32Helper.cs Updated GetWindowStyle and SetWindowStyle to use nint and GetWindowLongPtr
Flow.Launcher.Infrastructure/PInvokeExtensions.cs Refactored DllImport declarations and added GetWindowLongPtr logic for architecture-specific behavior
Flow.Launcher.Infrastructure/NativeMethods.txt Updated reference from GetWindowLong to WINDOW_LONG_PTR_INDEX

@Jack251970 Jack251970 enabled auto-merge May 24, 2025 05:12
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ check-file-path 1
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 13

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link

gitstream-cm bot commented May 24, 2025

🥷 Code experts: no user but you matched threshold 10

Jack251970 has most 👩‍💻 activity in the files.
Jack251970 has most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/NativeMethods.txt

Activity based on git-commit:

Jack251970
MAY 4 additions & 1 deletions
APR 0 additions & 5 deletions
MAR 40 additions & 5 deletions
FEB 4 additions & 1 deletions
JAN 1 additions & 4 deletions
DEC 24 additions & 2 deletions

Knowledge based on git-blame:
Jack251970: 93%

Flow.Launcher.Infrastructure/PInvokeExtensions.cs

Activity based on git-commit:

Jack251970
MAY
APR
MAR 25 additions & 0 deletions
FEB
JAN
DEC

Knowledge based on git-blame:
Jack251970: 100%

Flow.Launcher.Infrastructure/Win32Helper.cs

Activity based on git-commit:

Jack251970
MAY 74 additions & 0 deletions
APR 202 additions & 33 deletions
MAR 581 additions & 226 deletions
FEB 13 additions & 16 deletions
JAN 0 additions & 138 deletions
DEC 243 additions & 4 deletions

Knowledge based on git-blame:
Jack251970: 95%

To learn more about /:\ gitStream - Visit our Docs

Copy link

gitstream-cm bot commented May 24, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented May 24, 2025

📝 Walkthrough

Walkthrough

The changes introduce a managed wrapper for the native GetWindowLongPtr API, update relevant PInvoke declarations, and refactor helper methods to use the new pointer-based signatures. The code now consistently uses pointer-sized types for window long operations, improving architecture compatibility and aligning with native API expectations.

Changes

File(s) Change Summary
Flow.Launcher.Infrastructure/NativeMethods.txt Replaced "GetWindowLong" with "WINDOW_LONG_PTR_INDEX" in the native methods list.
Flow.Launcher.Infrastructure/PInvokeExtensions.cs Refactored PInvoke declarations for SetWindowLong/Ptr to private; added public GetWindowLongPtr wrapper and declarations.
Flow.Launcher.Infrastructure/Win32Helper.cs Updated method signatures and calls to use nint and GetWindowLongPtr/SetWindowLongPtr for window style operations.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Win32Helper
    participant PInvoke
    participant NativeAPI

    Caller->>Win32Helper: GetWindowStyle(hWnd, nIndex)
    Win32Helper->>PInvoke: GetWindowLongPtr(hWnd, nIndex)
    PInvoke->>NativeAPI: GetWindowLongPtr (native call)
    NativeAPI-->>PInvoke: nint value
    PInvoke-->>Win32Helper: nint value
    Win32Helper-->>Caller: nint value

    Caller->>Win32Helper: SetWindowStyle(hWnd, nIndex, newLong)
    Win32Helper->>PInvoke: SetWindowLongPtr(hWnd, nIndex, newLong)
    PInvoke->>NativeAPI: SetWindowLongPtr (native call)
    NativeAPI-->>PInvoke: nint result
    PInvoke-->>Win32Helper: nint result
    Win32Helper-->>Caller: nint result
Loading

Suggested labels

Dev branch only

Poem

In the warren of code, a pointer hops through,
From int to nint, a type fresh and new.
With window styles fetched and set just right,
The rabbits rejoice in the moon’s soft light.
🐇✨

"Hop on, dear bytes, across architectures true!"

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2026bb7 and b2f5713.

📒 Files selected for processing (3)
  • Flow.Launcher.Infrastructure/NativeMethods.txt (1 hunks)
  • Flow.Launcher.Infrastructure/PInvokeExtensions.cs (2 hunks)
  • Flow.Launcher.Infrastructure/Win32Helper.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
Flow.Launcher.Infrastructure/PInvokeExtensions.cs (1)
Flow.Launcher.Infrastructure/Win32Helper.cs (1)
  • HWND (330-338)
Flow.Launcher.Infrastructure/Win32Helper.cs (1)
Flow.Launcher.Infrastructure/PInvokeExtensions.cs (2)
  • PInvoke (7-45)
  • GetWindowLongPtr (39-44)
🪛 GitHub Check: Check Spelling
Flow.Launcher.Infrastructure/PInvokeExtensions.cs

[warning] 16-16:
Wnd is not a recognized word. (unrecognized-spelling)

🪛 GitHub Actions: Check Spelling
Flow.Launcher.Infrastructure/PInvokeExtensions.cs

[warning] 16-16: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 21-21: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 24-24: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 25-25: Wnd is not a recognized word. (unrecognized-spelling)

Flow.Launcher.Infrastructure/Win32Helper.cs

[warning] 18-18: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 41-41: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 41-41: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 52-52: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 53-53: DWMSBT is not a recognized word. (unrecognized-spelling)


[warning] 53-53: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 54-54: DWMSBT is not a recognized word. (unrecognized-spelling)


[warning] 54-54: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 55-55: DWMSBT is not a recognized word. (unrecognized-spelling)


[warning] 55-55: SYSTEMBACKDROP is not a recognized word. (unrecognized-spelling)


[warning] 58-58: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 58-58: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 60-60: DWMWA is not a recognized word. (unrecognized-spelling)


[warning] 60-60: DWMWINDOWATTRIBUTE is not a recognized word. (unrecognized-spelling)


[warning] 69-69: Dwm is not a recognized word. (unrecognized-spelling)


[warning] 69-69: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 71-71: DWMWA is not a recognized word. (unrecognized-spelling)


[warning] 71-71: DWMWINDOWATTRIBUTE is not a recognized word. (unrecognized-spelling)


[warning] 87-87: DWMWCP is not a recognized word. (unrecognized-spelling)


[warning] 88-88: DWMWCP is not a recognized word. (unrecognized-spelling)


[warning] 89-89: DWMWCP is not a recognized word. (unrecognized-spelling)


[warning] 93-93: PInvoke is not a recognized word. (unrecognized-spelling)


[warning] 95-95: DWMWA is not a recognized word. (unrecognized-spelling)


[warning] 95-95: DWMWINDOWATTRIBUTE is not a recognized word. (unrecognized-spelling)


[warning] 161-161: GWL is not a recognized word. (unrecognized-spelling)


[warning] 172-172: GWL is not a recognized word. (unrecognized-spelling)


[warning] 177-177: GWL is not a recognized word. (unrecognized-spelling)


[warning] 188-188: GWL is not a recognized word. (unrecognized-spelling)


[warning] 262-262: WINTAB is not a recognized word. (unrecognized-spelling)


[warning] 275-275: Progman is not a recognized word. (unrecognized-spelling)


[warning] 276-276: WORKERW is not a recognized word. (unrecognized-spelling)


[warning] 516-516: hkl is not a recognized word. (unrecognized-spelling)


[warning] 522-522: hkl is not a recognized word. (unrecognized-spelling)


[warning] 548-548: nqo is not a recognized word. (unrecognized-spelling)


[warning] 621-621: tsf is not a recognized word. (unrecognized-spelling)


[warning] 644-644: tsf is not a recognized word. (unrecognized-spelling)


[warning] 644-644: tsf is not a recognized word. (unrecognized-spelling)


[warning] 645-645: Tsf is not a recognized word. (unrecognized-spelling)


[warning] 681-681: Noto is not a recognized word. (unrecognized-spelling)


[warning] 682-682: Noto is not a recognized word. (unrecognized-spelling)


[warning] 683-683: Noto is not a recognized word. (unrecognized-spelling)


[warning] 684-684: Noto is not a recognized word. (unrecognized-spelling)


[warning] 725-725: noto is not a recognized word. (unrecognized-spelling)


[warning] 728-728: noto is not a recognized word. (unrecognized-spelling)


[warning] 730-730: noto is not a recognized word. (unrecognized-spelling)


[warning] 750-750: noto is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (8)
Flow.Launcher.Infrastructure/NativeMethods.txt (1)

25-25: LGTM! Correctly updated for pointer-sized operations.

The replacement of "GetWindowLong" with "WINDOW_LONG_PTR_INDEX" aligns with the architectural improvements in the related files, supporting both 32-bit and 64-bit operations.

Flow.Launcher.Infrastructure/PInvokeExtensions.cs (4)

9-11: Good documentation added.

The comments clearly indicate the purpose and source of the SetWindowLong implementation.


13-16: Proper encapsulation of native methods.

Changing the visibility to private static extern is correct since these are now implementation details wrapped by the public methods.

🧰 Tools
🪛 GitHub Check: Check Spelling

[warning] 16-16:
Wnd is not a recognized word. (unrecognized-spelling)

🪛 GitHub Actions: Check Spelling

[warning] 16-16: Wnd is not a recognized word. (unrecognized-spelling)


21-26: Excellent architecture-aware implementation.

The wrapper method correctly handles the CsWin32 limitation by using sizeof(nint) to determine the platform and calling the appropriate native function. This fixes the crash on x32 devices mentioned in the PR objectives.

🧰 Tools
🪛 GitHub Check: Check Spelling

[warning] 25-25:
Wnd is not a recognized word. (unrecognized-spelling)


[warning] 24-24:
Wnd is not a recognized word. (unrecognized-spelling)


[warning] 21-21:
Wnd is not a recognized word. (unrecognized-spelling)

🪛 GitHub Actions: Check Spelling

[warning] 21-21: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 24-24: Wnd is not a recognized word. (unrecognized-spelling)


[warning] 25-25: Wnd is not a recognized word. (unrecognized-spelling)


28-44: Well-implemented GetWindowLong wrapper following established pattern.

The implementation mirrors the SetWindowLongPtr pattern and correctly addresses the CsWin32 issue. The unsafe sizeof check and proper casting ensure compatibility across architectures.

The static analysis warnings about "Wnd" can be safely ignored as this is a standard Windows API abbreviation.

Flow.Launcher.Infrastructure/Win32Helper.cs (3)

195-203: Correct update to pointer-sized return type.

The change from int to nint for the return type is appropriate and aligns with the new GetWindowLongPtr API that handles pointer-sized values correctly across architectures.


205-216: Proper parameter type update for pointer-sized values.

The change from int to nint for the dwNewLong parameter correctly reflects the pointer-sized nature of window long values.


192-192: Correct usage of pointer-sized parameter.

This call correctly passes the nint value without unnecessary casting, maintaining type consistency with the updated method signature.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dev branch only An issue or fix for the Dev branch build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant