Skip to content

Convert To 'LibraryImport' with 'W' suffix creates invalid code #85578

@Symbai

Description

@Symbai

I have the following existing code:

[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Unicode)]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool Process32FirstW(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);

VS suggests me to convert it to LibraryImport, there is also an option to use W suffix:
image

I've chosen that and it created:

		[LibraryImport(Lib.Kernel32, EntryPoint = "Process32FirstWW", SetLastError = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static partial bool Process32FirstW(IntPtr hSnapshot, ref PROCESSENTRY32 lppe);

Obviously there is no such Process32FirstWW entrypoint. I don't know at which logic VS suggests sometimes only A prefix, sometimes only W prefix and sometimes no prefix at all. But seeing that there must be a logic somehow, the logic leads to invalid code at this point. For some people its obvious, for other people it might not. However I think that IF VS suggests to use W suffix which seems to be based on some logic, it must be correct, or it should just not show any suffix option at all (which VS is doing for some other pinvokes).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions