public static RenderingContext FromBitmapInfo( BitmapInfo bitmapInfo, PixelFormatDescriptor pfd, out IntPtr bitmapHandle) { IntPtr dc = WGL.GetDC(IntPtr.Zero); IntPtr compatibleDc = WGL.CreateCompatibleDC(dc); WGL.ReleaseDC(IntPtr.Zero, dc); IntPtr ppvBits; bitmapHandle = WGL.CreateDIBSection(compatibleDc, ref bitmapInfo, DIBDataType.RgbColors, out ppvBits, IntPtr.Zero, 0U); if (bitmapHandle == IntPtr.Zero) { throw new InternalException("Error in CreateDIBSection", (Exception) new Win32Exception(Marshal.GetLastWin32Error())); } if (WGL.SelectObject(compatibleDc, bitmapHandle) == IntPtr.Zero) { throw new InternalException("SelectObject failed"); } int pixelFormatIndex = RenderingContext.smethod_0(compatibleDc, pfd); IntPtr context = WGL.wglCreateContext(compatibleDc); if (context == IntPtr.Zero) { throw new InternalException("Error in wglCreateContext", (Exception) new Win32Exception(Marshal.GetLastWin32Error())); } return(new RenderingContext(IntPtr.Zero, compatibleDc, true, context, pixelFormatIndex)); }