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

WlanOpenHandle uses Microsoft.Win32.SafeHandles.SafeFileHandle #1656

Closed
Nuklon opened this issue Jul 26, 2023 · 4 comments
Closed

WlanOpenHandle uses Microsoft.Win32.SafeHandles.SafeFileHandle #1656

Nuklon opened this issue Jul 26, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@Nuklon
Copy link
Contributor

Nuklon commented Jul 26, 2023

Actual behavior

WlanOpenHandle function uses the Microsoft.Win32.SafeHandles.SafeFileHandle handle, but this is incorrect. It needs to be closed using WlanCloseHandle.

Expected behavior

A clear and concise description of what you expected to happen.

Repro steps

  1. NativeMethods.txt content:
WlanOpenHandle

Context

CsWin32 version: 0.3.18-beta+dc807e7787
Target Framework: net 6.0
LangVersion (if explicitly set by project): latest

@Nuklon Nuklon added the bug Something isn't working label Jul 26, 2023
@AArnott AArnott transferred this issue from microsoft/CsWin32 Jul 26, 2023
@AArnott
Copy link
Member

AArnott commented Jul 26, 2023

This issue needs to be fixed in the metadata.

@Nuklon
Copy link
Contributor Author

Nuklon commented Jul 27, 2023

This issue needs to be fixed in the metadata.

I checked the metadata but it's just using a HANDLE:

		[SupportedOSPlatform("windows6.0.6000")]
		[Documentation("https://docs.microsoft.com/windows/win32/api/wlanapi/nf-wlanapi-wlanopenhandle")]
		[DllImport("wlanapi.dll", ExactSpelling = true, PreserveSig = false)]
		public unsafe static extern uint WlanOpenHandle([In] uint dwClientVersion, [Reserved] [Optional] void* pReserved, [Out] uint* pdwNegotiatedVersion, [Out] HANDLE* phClientHandle);

@AArnott
Copy link
Member

AArnott commented Jul 27, 2023

That's the problem. In the metadata, using HANDLE means it is released by CloseHandle. In this case we need non-default behavior specified in the metadata.

@mikebattista
Copy link
Contributor

We can add RAIIFree to the HANDLE parameter.

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

No branches or pull requests

3 participants