Skip to content

Broken struct definition for MODULEENTRY32 #597

Closed

Description

Actual behavior

		internal partial struct MODULEENTRY32
		{
			internal uint dwSize;
			internal uint th32ModuleID;
			internal uint th32ProcessID;
			internal uint GlblcntUsage;
			internal uint ProccntUsage;
			internal unsafe byte* modBaseAddr;
			internal uint modBaseSize;
			internal winmdroot.Foundation.HINSTANCE hModule;
			internal unsafe winmdroot.Foundation.CHAR* szModule;
			internal unsafe winmdroot.Foundation.CHAR* szExePath;
		}

The szModule and szExePath fields are completely wrong and will lead to a failed Module32First call when the dwSize field is set to Unsafe.SizeOf<MODULEENTRY32>().

Expected behavior

https://docs.microsoft.com/en-us/windows/win32/api/tlhelp32/ns-tlhelp32-moduleentry32

Repro steps

  1. NativeMethods.txt content:
CreateToolhelp32Snapshot
Module32First
Module32Next

Context

  • CsWin32 version: 0.2.1-beta
  • Win32Metadata version (if explicitly set by project): 24.0.1-preview
  • Target Framework: net7.0
  • LangVersion (if explicitly set by project): latest

Activity

  1. AArnott commented on Jul 2, 2022

    @AArnott
    Member

    These two fields should be fixed-length inline arrays.

  2. AArnott commented on Jul 2, 2022

    @AArnott
    Member

    It only repros for me when allowMarshaling: false.

  3. alexrp commented on Jul 2, 2022

    @alexrp
    Author

    It only repros for me when allowMarshaling: false.

    Ah, you're right, I forgot to include that I have that set, sorry.

  4. AArnott commented on Jul 2, 2022

    @AArnott
    Member

    Not a big problem. I kinda accidentally repro'd it once, then it disappeared, so I was able to figure it out. Thanks for the report. I'll get it fixed.

  5. alexrp commented on Jul 12, 2022

    @alexrp
    Author

    Andrew Arnott (@AArnott) any chance a release with this fix could be pushed soon-ish? I keep running into this in various structs and it's getting harder and harder to work around - structs with inline arrays in the middle, for example, are almost impossible to work with.

  6. AArnott commented on Jul 12, 2022

    @AArnott
    Member

    Alex Rønne Petersen (@alexrp) 0.2.10-beta is going to nuget.org now.

  7. alexrp commented on Jul 13, 2022

    @alexrp
    Author

    I can confirm the fix works on my end as well. Thanks!

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

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions