Skip to content
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

PrivateExtractIcons method incorrectly claims piconid parameter is an array #614

Closed
Craftplacer opened this issue Aug 2, 2021 · 1 comment
Assignees
Labels
broken api An API is inaccurate and could lead to runtime failure

Comments

@Craftplacer
Copy link

Actual behavior

PrivateExtractIcons is failing because nIcons is set to zero, the only way to set it to a valid value is to use the "unmanaged" method overload (that uses unsafe pointers). I don't know why nIcons isn't part of the managed function signature.

image

In this screenshot, there's a call visible done by a referenced DLL (shell32.dll) that calls the function correctly, while the .NET runtime (user code, coreclr.dll) is calling the function with nIcons set to 0 (also causing the entry to be highlighted as yellow indicating an error).

Expected behavior

To have uint nIcons inside the method overload using managed objects:

PrivateExtractIcons(string szFileName, int nIconIndex, int cxIcon, int cyIcon, out DestroyIconSafeHandle phicon, Span<uint> piconid, /*uint nIcons*/, uint flags)

Repro steps

  1. NativeMethods.txt content:
PrivateExtractIcons
  1. Any of your own code that should be shared?
var result = PInvoke.PrivateExtractIcons(@"C:\Windows\system32\shell32.dll", -33, 32, 32, out var hIcon, null, 0);

In this example hIcon is NULL and the result is also 0, indicating this function did nothing or has failed.

Context

  • CsWin32 version: 0.1.506-beta
  • Target Framework: net5.0-windows
@AArnott
Copy link
Member

AArnott commented Aug 18, 2021

The parameter is removed from the friendly overload because it can be inferred from the length of the phicon array.
However the metadata is buggy for this method. It claims that both phicon and piconid are arrays, both of which have a length set by nIcons. But per the docs piconid is not an array at all.
When the metadata is fixed, the missing parameter in the friendly overload will still be missing, but you'll be able to set its value by allocating the proper span for the phicon argument.

@AArnott AArnott transferred this issue from microsoft/CsWin32 Aug 18, 2021
@AArnott AArnott changed the title Safe method overload for PrivateExtractIconsW is missing parameter nIcons PrivateExtractIcons method incorrectly claims two pointer parameters are arrays Aug 18, 2021
@AArnott AArnott changed the title PrivateExtractIcons method incorrectly claims two pointer parameters are arrays PrivateExtractIcons method incorrectly claims piconid parameter is an array Aug 18, 2021
@AArnott AArnott added the broken api An API is inaccurate and could lead to runtime failure label Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure
Projects
None yet
Development

No branches or pull requests

3 participants