Skip to content

Fix hardcoded PInvoke class name in ICCloseSafeHandle generation#1697

Merged
jevansaks merged 1 commit into
mainfrom
fix/issue-1696-hardcoded-pinvoke-classname
May 20, 2026
Merged

Fix hardcoded PInvoke class name in ICCloseSafeHandle generation#1697
jevansaks merged 1 commit into
mainfrom
fix/issue-1696-hardcoded-pinvoke-classname

Conversation

@jevansaks
Copy link
Copy Markdown
Member

Summary

Fixes #1696 — When a custom className is configured in NativeMethods.json, the generated ICCloseSafeHandle.ReleaseHandle() method incorrectly referenced PInvoke.ICERR_OK instead of using the configured class name (e.g., MyPInvoke.ICERR_OK).

Changes

  • src/Microsoft.Windows.CsWin32/Generator.Handle.cs: Replaced hardcoded IdentifierName("PInvoke") with this.methodsAndConstantsClassName which correctly reflects the configured className option.
  • test/CsWin32Generator.Tests/CsWin32GeneratorTests.cs: Added ICCloseSafeHandle_CustomClassName test that verifies ICOpen generation (which produces ICCloseSafeHandle) compiles successfully with both default and custom class names.

When a custom className is configured in NativeMethods.json, the
ICCloseSafeHandle.ReleaseHandle() method incorrectly referenced
'PInvoke.ICERR_OK' instead of using the configured class name.

This replaces the hardcoded IdentifierName("PInvoke") with the
existing this.methodsAndConstantsClassName field which correctly
reflects the user's configured className option.

Fixes #1696

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jevansaks jevansaks marked this pull request as ready for review May 20, 2026 15:44
@jevansaks jevansaks enabled auto-merge (squash) May 20, 2026 15:50
@jevansaks jevansaks merged commit 657d346 into main May 20, 2026
18 checks passed
@jevansaks jevansaks deleted the fix/issue-1696-hardcoded-pinvoke-classname branch May 20, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken code generated due to hardcoded "PInvoke" classname

2 participants