mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 04:58:24 +01:00
Public-PR: https://github.com/ahwootech/BRUTAL/pull/9 Public-PR: https://github.com/ahwootech/BRUTAL/pull/15 Public-PR: https://github.com/ahwootech/BRUTAL/pull/21 Fixes: ahwootech/BRUTAL#8 Fixes: ahwootech/BRUTAL#22 Co-authored-by: Laurens de Voogd <laurens@devoogd.be> Co-authored-by: sGo7-Dev <goulax16@gmail.com> Co-authored-by: Capsup <capsup@live.dk>
18 lines
710 B
C#
18 lines
710 B
C#
using System.Runtime.InteropServices.Marshalling;
|
|
|
|
namespace Brutal.SlangApi;
|
|
|
|
// Slang's direct interface-returning getters/loaders lend a reference. The RCW
|
|
// takes its own reference, but the returned pointer must not be released by the stub.
|
|
[CustomMarshaller(
|
|
typeof(CustomMarshallerAttribute.GenericPlaceholder),
|
|
MarshalMode.Default,
|
|
typeof(BorrowedSlangInterfaceMarshaller<>)
|
|
)]
|
|
internal static unsafe class BorrowedSlangInterfaceMarshaller<T>
|
|
where T : class
|
|
{
|
|
public static T? ConvertToManaged(void* unmanaged) => Slang.WrapBorrowedComInstance<T>((nint)unmanaged);
|
|
|
|
public static void* ConvertToUnmanaged(T? managed) => ComInterfaceMarshaller<T>.ConvertToUnmanaged(managed);
|
|
}
|