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

Broken struct definition for MODULEENTRY32 #597

Closed
alexrp opened this issue Jul 1, 2022 · 7 comments · Fixed by #599
Closed

Broken struct definition for MODULEENTRY32 #597

alexrp opened this issue Jul 1, 2022 · 7 comments · Fixed by #599
Assignees
Labels
bug Something isn't working

Comments

@alexrp
Copy link

alexrp commented Jul 1, 2022

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
@alexrp alexrp added the bug Something isn't working label Jul 1, 2022
@AArnott
Copy link
Member

AArnott commented Jul 2, 2022

These two fields should be fixed-length inline arrays.

@AArnott
Copy link
Member

AArnott commented Jul 2, 2022

It only repros for me when allowMarshaling: false.

@alexrp
Copy link
Author

alexrp commented Jul 2, 2022

It only repros for me when allowMarshaling: false.

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

@AArnott AArnott self-assigned this Jul 2, 2022
@AArnott
Copy link
Member

AArnott commented Jul 2, 2022

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.

alexrp added a commit to vezel-dev/novadrop that referenced this issue Jul 2, 2022
AArnott added a commit that referenced this issue Jul 5, 2022
AArnott added a commit that referenced this issue Jul 5, 2022
@alexrp
Copy link
Author

alexrp commented Jul 12, 2022

@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.

@AArnott
Copy link
Member

AArnott commented Jul 12, 2022

@alexrp 0.2.10-beta is going to nuget.org now.

@alexrp
Copy link
Author

alexrp commented Jul 13, 2022

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

alexrp added a commit to vezel-dev/novadrop that referenced this issue Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants