// static factory methods public static Program CreateProgramWithSource(Context context, string[] sources) { ErrorCode error; IntPtr[] buffers = new IntPtr[sources.Length]; for (var i = 0; i < sources.Length; i++) { buffers[i] = Marshal.StringToHGlobalAnsi(sources[i]); } IntPtr[] lengths = new IntPtr[sources.Length]; for (var i = 0; i < sources.Length; i++) { lengths[i] = (IntPtr)sources[i].Length; } var handle = NativeMethods.clCreateProgramWithSource(context.handle, (uint)sources.Length, sources, lengths, out error); for (var i = 0; i < sources.Length; i++) { Marshal.FreeHGlobal(buffers[i]); } if (error != ErrorCode.Success) { throw new OpenClException(error); } return(new Program(handle)); }