public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen) { //For ImgCbShow Bitmap tmpCallBack = new Bitmap(_previewWidth, _previewHeight, _previewStride, PixelFormat.Format24bppRgb, pBuffer); tmpCallBack.RotateFlip(RotateFlipType.RotateNoneFlipXY); ImgCbShow.Image = tmpCallBack.Clone(new Rectangle(0, 0, tmpCallBack.Width, tmpCallBack.Height), tmpCallBack.PixelFormat); //For ImgSrcShow (Can't used for rotating 90 or 270) Bitmap tmpSrc = new Bitmap(_previewWidth, _previewHeight, _previewStride, PixelFormat.Format24bppRgb, pBuffer); tmpSrc.RotateFlip(RotateFlipType.RotateNoneFlipX); int step; int iWidth = tmpSrc.Width; int iHeight = tmpSrc.Height; Rectangle rect = new Rectangle(0, 0, tmpSrc.Width, tmpSrc.Height); BitmapData bmpData = tmpSrc.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); IntPtr iPtr = bmpData.Scan0; MemoryCtrl.MemoryCopy(pBuffer, BufferLen, iPtr); step = bmpData.Stride; int iBytes = step * iHeight; //byte[] PixelValues = new byte[iBytes]; //Marshal.Copy(iPtr, PixelValues, 0, iBytes); //Marshal.Copy(PixelValues, 0, pBuffer, iBytes); tmpSrc.UnlockBits(bmpData); return(0); }
/// <inheritdoc /> /// <summary> /// </summary> public void Dispose() { MemoryCtrl.FreeMemoryEx(lpReserved2); MemoryCtrl.FreeMemoryEx(hStdError); MemoryCtrl.FreeMemoryEx(hStdInput); MemoryCtrl.FreeMemoryEx(hStdOutput); }
/// <summary> /// /// </summary> /// <param name="processInformation"></param> public PROCESS_INFORMATION(PROCESS_INFORMATION processInformation) : this() { ProcessId = processInformation.ProcessId; ThreadId = processInformation.ThreadId; hProcess = MemoryCtrl.CopyMemoryEx(processInformation.hProcess); hThread = MemoryCtrl.CopyMemoryEx(processInformation.hThread); }
/// <summary> /// /// </summary> /// <param name="startupInfo"></param> public STARTUPINFO(STARTUPINFO startupInfo) : this() { cb = startupInfo.cb; cbReserved2 = startupInfo.cbReserved2; lpDesktop = startupInfo.lpDesktop; lpReserved = startupInfo.lpReserved; lpTitle = startupInfo.lpTitle; dwFillAttribute = startupInfo.dwFillAttribute; dwFlags = startupInfo.dwFlags; dwX = startupInfo.dwX; dwXCountChars = startupInfo.dwXCountChars; dwXSize = startupInfo.dwXSize; dwY = startupInfo.dwY; dwYCountChars = startupInfo.dwYCountChars; dwYSize = startupInfo.dwYSize; lpReserved2 = MemoryCtrl.CopyMemoryEx(startupInfo.lpReserved2); hStdError = MemoryCtrl.CopyMemoryEx(startupInfo.hStdError); hStdInput = MemoryCtrl.CopyMemoryEx(startupInfo.hStdInput); hStdOutput = MemoryCtrl.CopyMemoryEx(startupInfo.hStdOutput); }
/// <summary> /// /// </summary> public void Start(int milliSeconds = 0) { if (string.IsNullOrEmpty(AppPath)) { throw new InvalidOperationException(); } var cmd = $"{AppPath} {Arguments}"; var sap = new SECURITY_ATTRIBUTES { lpSecurityDescriptor = IntPtr.Zero, bInheritHandle = true }; sap.nLength = Marshal.SizeOf(sap); var ptrsap = MemoryCtrl.CopyMemoryEx(sap); var sat = new SECURITY_ATTRIBUTES { lpSecurityDescriptor = IntPtr.Zero, bInheritHandle = true }; sat.nLength = Marshal.SizeOf(sat); var ptrsat = MemoryCtrl.CopyMemoryEx(sat); if (!NativeMethods.CreateProcess(null, cmd, ptrsap, ptrsat, true, 0, IntPtr.Zero, null, ref StartupInfo, out ProcessInformation)) { throw new Exception($"Error!\nCode: {NativeMethods.GetLastError()}"); } MemoryCtrl.FreeMemoryEx(ptrsat); MemoryCtrl.FreeMemoryEx(ptrsap); if (milliSeconds > 0) { WaitForExit(milliSeconds); } }
/// <inheritdoc /> /// <summary> /// </summary> public void Dispose() { MemoryCtrl.FreeMemoryEx(lpSecurityDescriptor); }
/// <summary> /// /// </summary> /// <param name="securityAttributes"></param> public SECURITY_ATTRIBUTES(SECURITY_ATTRIBUTES securityAttributes) : this() { nLength = securityAttributes.nLength; bInheritHandle = securityAttributes.bInheritHandle; lpSecurityDescriptor = MemoryCtrl.CopyMemoryEx(securityAttributes.lpSecurityDescriptor); }
/// <inheritdoc /> /// <summary> /// </summary> public void Dispose() { MemoryCtrl.FreeMemoryEx(hProcess); MemoryCtrl.FreeMemoryEx(hThread); }