microsoft / microsoft/CsWin32

IDataTransferManagerInterop with void** parameter

Open
#246 14 comments 0 reactions 1 assignee View on GitHub

@sotteson1 is already working on this.

Since Sep 29, 2021.

Dominant language
C#
Stars
2.5k
Forks
124
Avg merge
1d 3h
Merged PRs (30d)
9

Description

Actual behavior

When I try to use IDataTransferManagerInterop the generated code uses a void** to return the requested DataTransferManager. I believe more comfortable code can and should be generated e.g. using an out DataTansferManager parameter.

Generated code:

[Guid("3A3DCD6C-3EAB-43DC-BCDE-45671CE800C8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport]
public interface IDataTransferManagerInterop
{
    unsafe void GetForWindow(HWND appWindow, global::System.Guid*riid, [Optional] void **dataTransferManager);
    void ShowShareUIForWindow(HWND appWindow);
}

as well as

    public static partial class FriendlyOverloadExtensions
    {
        public static unsafe void GetForWindow(this IDataTransferManagerInterop @this, HWND appWindow, in global::System.Guid riid, void **dataTransferManager)
        {
            // ...
        }
    }

Expected behavior

The generated code works. The unsafe nature of a void** pointer and the complexity to arrive at a working implementation lead me to file this issue.

Repro steps

  1. NativeMethods.txt content:
IDataTransferManagerInterop
  1. NativeMethods.json content (if present):
{
  "$schema": "https://aka.ms/CsWin32.schema.json",
  "public": true
}
  1. Any of your own code that should be shared?
using WinRT;
// riid of DataTransferManager, not IDataTransferManagerInterop 
var guid = Guid.Parse("a5caee9b-8708-49d1-8d36-67d25a8da00c"); 
var iop = DataTransferManager.As<IDataTransferManagerInterop>();
var transferManager = IntPtr.Zero;
iop.GetForWindow(PInvoke.GetActiveWindow(), guid, (void**)&transferManager);
var realManager = DataTransferManager.FromAbi(transferManager);
Context
  • CsWin32 version: 0.1.445-beta
  • Target Framework: .net 5.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.