Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / WPF

Using Direct2D with WPF

Rate me:
Please Sign up or sign in to vote.
4.96/5 (28 votes)
3 Nov 2010CPOL11 min read 188.8K   6.1K   65  
Hosting Direct2D content in WPF controls.
using System;
using System.Runtime.InteropServices;

namespace Direct2D.Interop
{
    internal sealed class Direct3DSurface9 : IDisposable
    {
        private ComInterface.IDirect3DSurface9 comObject;
        private IntPtr native;

        internal Direct3DSurface9(ComInterface.IDirect3DSurface9 obj)
        {
            this.comObject = obj;
            this.native = Marshal.GetIUnknownForObject(this.comObject);
        }

        ~Direct3DSurface9()
        {
            this.Release();
        }

        public IntPtr NativeInterface
        {
            get { return this.native; }
        }

        public void Dispose()
        {
            this.Release();
            GC.SuppressFinalize(this);
        }

        private void Release()
        {
            if (this.comObject != null)
            {
                Marshal.Release(this.native);
                this.native = IntPtr.Zero;

                Marshal.ReleaseComObject(this.comObject);
                this.comObject = null;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions