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

Some samples use WindowsRuntimeMarshal class, that is no longer available in .NET 5+ #110

Closed
lostmsu opened this issue May 22, 2022 · 4 comments

Comments

@lostmsu
Copy link

lostmsu commented May 22, 2022

Is there a replacement for .NET 5+?

Example:

public static GraphicsCaptureItem CreateItemForMonitor(IntPtr hmon)
{
    var factory = WindowsRuntimeMarshal.GetActivationFactory(typeof(GraphicsCaptureItem));
    var interop = (IGraphicsCaptureItemInterop)factory; 
    var itemPointer = interop.CreateForMonitor(hmon, GraphicsCaptureItemGuid);
    var item = Marshal.GetObjectForIUnknown(itemPointer) as GraphicsCaptureItem;
    Marshal.Release(itemPointer);

    return item;
}
@robmikh
Copy link
Member

robmikh commented May 22, 2022

Take a look at this file:

https://github.com/robmikh/WPFCaptureSample/blob/master/Robmikh.WindowsRuntimeHelpers/CaptureHelper.cs

That repo has a version of the WPF capture sample that's been updated for .NET 5/6.

@lostmsu
Copy link
Author

lostmsu commented May 22, 2022

@robmikh that did not immediately work due to my need to understand CSWinRT, so I ended up not using your code. But simply following this table I got a working sample, that does not need to use CSWinRT magic explicitly, and does not require unsafe:

public static GraphicsCaptureItem CreateItemForMonitor(IntPtr hmon)
{
    var factory = GraphicsCaptureItem.As<IGraphicsCaptureItemInterop>();
    var itemPointer = factory.CreateForMonitor(hmon, GraphicsCaptureItemGuid);
    var item = GraphicsCaptureItem.FromAbi(itemPointer);
    Marshal.Release(itemPointer);

    return item;
}

@robmikh robmikh closed this as completed May 22, 2022
@lostmsu
Copy link
Author

lostmsu commented May 23, 2022

@robmikh no plans to update the samples in this repo?

@robmikh
Copy link
Member

robmikh commented May 23, 2022

It's on the list, currently getting the C++ samples updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants