Skip to content

refactor: use [LibraryImport] for SHEmptyRecycleBin#853

Merged
laurentiu021 merged 1 commit into
mainfrom
refactor/r8-libraryimport-emptyrecyclebin
Jun 11, 2026
Merged

refactor: use [LibraryImport] for SHEmptyRecycleBin#853
laurentiu021 merged 1 commit into
mainfrom
refactor/r8-libraryimport-emptyrecyclebin

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

Summary

Converts the SHEmptyRecycleBin P/Invoke from the runtime-marshalled [DllImport]
to the source-generated [LibraryImport]. Behavior is identical — the generator
emits the same UTF-16, W-suffixed entry-point call, just with the marshalling stub
produced at build time instead of by the runtime.

Change

Services/TuneUpService.cs:

  • TuneUpService and its nested NativeMethods are now partial (required so the
    generator can emit the implementation).
  • [DllImport("shell32.dll", CharSet = CharSet.Unicode)] static extern
    [LibraryImport("shell32.dll", StringMarshalling = StringMarshalling.Utf16, EntryPoint = "SHEmptyRecycleBinW")] static partial.

Why identical

  • CharSet.UnicodeStringMarshalling.Utf16 — same UTF-16 string marshalling.
  • EntryPoint = "SHEmptyRecycleBinW" names the exact W-suffixed export that
    CharSet.Unicode was already selecting implicitly.
  • Signature is otherwise blittable (IntPtr, uint, int HRESULT return) — no
    marshalling behavior changes. Neither the old nor new declaration sets
    SetLastError, so error handling (the hr >= 0 || 0x80070012 check) is unchanged.

Not converted (deliberately)

The other two [DllImport]s — SHGetFileInfo (ref SHFILEINFO, ByValTStr inline
buffers) and SHFileOperation (ref SHFILEOPSTRUCT, LPWStr fields) — pass
non-blittable structs the source generator cannot marshal without a custom
[NativeMarshalling] rewrite, which would not be byte-identical. They stay
[DllImport].

Verification

  • Build: main + Tests + IntegrationTests all 0 warnings / 0 errors (the generator
    accepted the signature).

Behavior identical (Protocol Q). refactor: → no release.

@laurentiu021 laurentiu021 merged commit ce06710 into main Jun 11, 2026
4 checks passed
@laurentiu021 laurentiu021 deleted the refactor/r8-libraryimport-emptyrecyclebin branch June 11, 2026 13:05
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.

1 participant