Skip to content

Ability to turn off usage of safe handles in overloads #605

Closed

Description

@fernandanavamoya

Is your feature request related to a problem? Please describe.
In Windows Forms we generally don't use safe handle in our interop but we do use string marshalling. In order to use the friendly overloads we need to turn off the usage of safe handles.

For example, this:

IntPtr threadHandle = (ctx is null ? IntPtr.Zero : ctx.GetHandle());

if (threadHandle != IntPtr.Zero)
{
    Kernel32.GetExitCodeThread(threadHandle, out uint exitCode);

Becomes this:

nint threadHandle = (ctx is null ? 0 : ctx.GetHandle());

if (threadHandle != 0)
{
     uint exitCode;
     PInvoke.GetExitCodeThread((Foundation.HANDLE)threadHandle, &exitCode);

Describe the solution you'd like
An option to disable safe handle usage.

Activity

  1. added
    enhancement
    on Jul 18, 2022
  2. JeremyKuhne commented on Jul 21, 2022

    @JeremyKuhne
    Member

    This blocked us from using HMODULE GetModuleHandle(PCWSTR) as we couldn't hack around the generated easy wrapper that returned the SafeHandle. We had to use GetModuleHandleEx to avoid getting a safe handle. There is also a bug in the generated GetModuleHandle safe overload, opening a bug on it.

  3. JeremyKuhne commented on Jul 21, 2022

    @JeremyKuhne
    Member

    The GetModuleHandle bug: #616

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

Metadata

Metadata

Labels

enhancementpartner

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions