Skip to content

PAINTSTRUCT rgbReserved field is missing size #215

Closed

Description

The definition of PAINSTRUCT (see https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-paintstruct) is:

typedef struct tagPAINTSTRUCT {
  HDC  hdc;
  BOOL fErase;
  RECT rcPaint;
  BOOL fRestore;
  BOOL fIncUpdate;
  BYTE rgbReserved[32];
} PAINTSTRUCT, *PPAINTSTRUCT, *NPPAINTSTRUCT, *LPPAINTSTRUCT;

However, the win32metadata definition of PAINTSTRUCT is missing the length of the rgbReserved array field:

public struct PAINTSTRUCT
{
	public HDC hdc;
	public BOOL fErase;
	public RECT rcPaint;
	public BOOL fRestore;
	public BOOL fIncUpdate;
	public byte[] rgbReserved;
}

Granted the Clr doesn't support statically sized arrays like C/C++. However, as I understand from looking at other examples, this information can be represented using NativeTypeInfoAttribute.SizeConst (along with LPArray as the UnmanagedType). I expect it would look something like this:

public struct PAINTSTRUCT
{
	public HDC hdc;
	public BOOL fErase;
	public RECT rcPaint;
	public BOOL fRestore;
	public BOOL fIncUpdate;
        [NativeTypeInfo(UnmanagedType.LPArray, SizeConst = 32)]
	public byte[] rgbReserved;
}

Activity

  1. AArnott commented on Feb 9, 2021

    @AArnott
    Member

    Granted the Clr doesn't support statically sized arrays like C/C++.

    It does, actually. C# as a language has only limited support so when "decompiling" the metadata to C# you don't see it, but indeed the metadata does reflect the 32-byte fixed length of the inline array:

    image

    When reading the metadata, be sure to use a parser that recognizes this.

  2. marler8997 commented on Feb 9, 2021

    @marler8997
    ContributorAuthor

    I stand corrected. Thanks for the info.

  3. marler8997 commented on Feb 9, 2021

    @marler8997
    ContributorAuthor

    I've found this this size information is available in the C# MetadataReader via the ArrayShape struct associated with the field type. However, it seems odd that this information is not reported by ILSpy, maybe an issue should be filed for ILSpy to report ArrayShape information? Then again, since ILSpy decompiles to C#, there's no way to represent this information in the language, so it might have to be in the form of a comment in the decompiled code? Does this seem like a reasonable course or maybe it's not a big deal? I could be missing something here so let me know if I am.

  4. AArnott commented on Feb 9, 2021

    @AArnott
    Member

    The screenshot I included above comes from ILSpy.
    But yes, in C# decompiler mode, it could only express it as a code comment. Feel free to file a request against ILSpy separately.

  5. marler8997 commented on Feb 9, 2021

    @marler8997
    ContributorAuthor

    Oh I didn't know ILSpy had different decompile modes. Thanks for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions