public void GetCallbackPtrReturnsPointerToShadow() { using (var callback = new CallbackImpl()) { Assert.NotEqual(IntPtr.Zero, CppObject.ToCallbackPtr <ICallback>(callback)); } }
public void GetCallbackPtrForClassWithMultipleInheritenceShouldReturnPointer() { using var callback = new Callback2Impl(); Assert.NotEqual(IntPtr.Zero, CppObject.ToCallbackPtr <ICallback>(callback)); Assert.NotEqual(IntPtr.Zero, CppObject.ToCallbackPtr <ICallback2>(callback)); }
private static Result RawD3D11CreateDeviceNoDeviceAndContext( IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out FeatureLevel featureLevel) { unsafe { var adapterPtr = CppObject.ToCallbackPtr <IDXGIAdapter>(adapter); fixed(void *featureLevelPtr = &featureLevel) { Result result = D3D11CreateDevice_( (void *)adapterPtr, (int)driverType, null, (int)flags, featureLevels != null && featureLevels.Length > 0 ? Unsafe.AsPointer(ref featureLevels[0]) : null, featureLevels?.Length ?? 0, SdkVersion, null, featureLevelPtr, null); GC.KeepAlive(adapter); return(result); } } }
unsafe IntPtr IStateSubObjectDescriptionMarshal.__MarshalAlloc(Dictionary <StateSubObject, IntPtr> subObjectLookup) { __Native *native = (__Native *)Marshal.AllocHGlobal(sizeof(__Native)); native->RootSignature = CppObject.ToCallbackPtr <ID3D12RootSignature>(RootSignature); return((IntPtr)native); }
public unsafe Result SetDevice(IUnknown device) { IntPtr devicePtr = CppObject.ToCallbackPtr <SharpGen.Runtime.IUnknown>(device); Result result = LocalInterop.CalliStdCallint(_nativePointer, devicePtr.ToPointer(), (*(void ***)_nativePointer)[3]); GC.KeepAlive(device); return(result); }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.RootSignature = CppObject.ToCallbackPtr <ID3D12RootSignature>(RootSignature); ComputeShader?.__MarshalTo(ref @ref.CS); @ref.NodeMask = NodeMask; CachedPSO.__MarshalTo(ref @ref.CachedPSO); @ref.Flags = Flags; }
internal static unsafe Result D3D12CreateDeviceNoDevice(IUnknown adapter, FeatureLevel minFeatureLevel) { var adapterPtr = CppObject.ToCallbackPtr <IUnknown>(adapter); var riid = typeof(ID3D12Device).GUID; var result = D3D12CreateDevice_((void *)adapterPtr, (int)minFeatureLevel, &riid, null); GC.KeepAlive(adapter); return(result); }
public void CanRoundTripCallThroughNativeVtblToManagedObject() { using var callback = new CallbackImpl(); var callbackPtr = CppObject.ToCallbackPtr <ICallback>(callback); var methodPtr = Marshal.ReadIntPtr(Marshal.ReadIntPtr(callbackPtr)); var delegateObject = Marshal.GetDelegateForFunctionPointer <CallbackShadow.CallbackVbtl.IncrementDelegate>(methodPtr); Assert.Equal(3, delegateObject(callbackPtr, 2)); }
private static IDisposable SetupTests(bool supportExceptions, out CallbackInterfaceNative nativeView, out ManagedImplementation target) { target = supportExceptions ? new ExceptionEnabledManagedImplementation() : new ManagedImplementation(); nativeView = new CallbackInterfaceNative(CppObject.ToCallbackPtr <CallbackInterface>(target)); return(new CompositeDisposable { target, nativeView }); }
private static unsafe int LoadSource(IntPtr thisObject, void *param0, void *param1) { try { IntPtr filenameRef = (IntPtr)param0; IDxcIncludeHandler @this = (IDxcIncludeHandler)ToShadow <Vortice.Dxc.IDxcIncludeHandlerShadow>(thisObject).Callback; string fileName = Marshal.PtrToStringUni(filenameRef); Result result = @this.LoadSource(fileName, out IDxcBlob includeSource); ref IntPtr includeSourceOut = ref Unsafe.AsRef <IntPtr>(param1); includeSourceOut = CppObject.ToCallbackPtr <IDxcBlob>(includeSource); return(result.Code); }
private int CreateCustomEffectImpl(out IntPtr nativeCustomEffectPtr) { nativeCustomEffectPtr = IntPtr.Zero; try { var customEffect = _createID2D1EffectImplFunc(); nativeCustomEffectPtr = CppObject.ToCallbackPtr <ID2D1EffectImpl>(customEffect); } catch (SharpGenException ex) { return(ex.HResult); } return(Result.Ok.Code); }
unsafe IntPtr IStateSubObjectDescriptionMarshal.__MarshalAlloc(Dictionary <StateSubObject, IntPtr> subObjectLookup) { __Native *native = (__Native *)Marshal.AllocHGlobal(sizeof(__Native)); native->pExistingCollection = CppObject.ToCallbackPtr <ID3D12StateObject>(ExistingCollection); native->NumExports = Exports?.Length ?? 0; if (native->NumExports > 0) { var nativeExports = (ExportDescription.__Native *)Interop.Alloc <ExportDescription.__Native>(native->NumExports); for (int i = 0; i < native->NumExports; i++) { Exports[i].__MarshalTo(ref nativeExports[i]); } native->pExports = nativeExports; } return((IntPtr)native); }
private static Result RawD3D11CreateDeviceNoContext( IDXGIAdapter adapter, DriverType driverType, DeviceCreationFlags flags, FeatureLevel[] featureLevels, out ID3D11Device device, out FeatureLevel featureLevel) { unsafe { device = default; var adapterPtr = CppObject.ToCallbackPtr <IDXGIAdapter>(adapter); fixed(void *featureLevelsPtr = &featureLevels[0]) fixed(void *featureLevelPtr = &featureLevel) { var devicePtr = IntPtr.Zero; Result result = D3D11CreateDevice_( (void *)adapterPtr, (int)driverType, null, (int)flags, featureLevels != null && featureLevels.Length > 0 ? featureLevelsPtr : null, featureLevels?.Length ?? 0, SdkVersion, &devicePtr, featureLevelPtr, null); if (result.Success && devicePtr != IntPtr.Zero) { device = new ID3D11Device(devicePtr); } GC.KeepAlive(adapter); return(result); } } }
protected DrawingSurfaceBackgroundContentProviderNativeBase() { thisComObjectPtr = CppObject.ToCallbackPtr <IDrawingSurfaceBackgroundContentProviderNative>(this); }
internal GameWindowPhoneXaml() { thisComObjectPtr = CppObject.ToCallbackPtr<IDrawingSurfaceContentProviderNative>(this); synchronizedTexture = null; }
internal GameWindowPhoneBackgroundXaml() { thisComObjectPtr = CppObject.ToCallbackPtr <IDrawingSurfaceBackgroundContentProviderNative>(this); }
public IntPtr GetNewIntPtr() => CppObject.ToCallbackPtr <ManagedCallback>(this);
public AutoShadowTests() { target = new ManagedImplementation(); nativeView = new CallbackInterfaceNative(CppObject.ToCallbackPtr <CallbackInterface>(target)); }
/// <summary> /// Return a pointer to the unmanaged version of this callback. /// </summary> /// <param name="callback">The callback.</param> /// <returns>A pointer to a shadow c++ callback</returns> public static IntPtr ToIntPtr(ManagerEventHandler callback) { return(CppObject.ToCallbackPtr <ManagerEventHandler>(callback)); }
/// <summary> /// Return a pointer to the unmanaged version of this callback. /// </summary> /// <param name="callback">The callback.</param> /// <returns>A pointer to a shadow c++ callback</returns> public static IntPtr ToIntPtr(PriorityComparison callback) { return(CppObject.ToCallbackPtr <PriorityComparison>(callback)); }