public static Context CreateContextFromType(Platform platform, DeviceType type, ContextNotify callback, object userData) { var pty = platform != null ? new ContextProperty[] { new ContextProperty(ContextProperties.Platform, platform.handle), ContextProperty.Zero } : null; var pfn = (ContextNotifyData)null; var pcb = (ContextNotifyInternal)null; var ptr = IntPtr.Zero; if (callback != null) { pfn = new ContextNotifyData(callback, userData); pcb = ContextNotifyData.Callback; ptr = pfn.Handle; } var err = ErrorCode.Success; var ctx = NativeMethods.clCreateContextFromType(pty, type, pcb, ptr, out err); if (err != ErrorCode.Success) { throw new OpenClException(err); } return(new Context(ctx, pfn)); }