■ DuplicateHandle API 함수를 선언하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using System; using System.Runtime.InteropServices; #region 핸들 복제하기 - DuplicateHandle(sourceProcessHandle, sourceHandle, targetProcessHandle, targetHandle, desiredAccess, inheritHandle, option) /// <summary> /// 핸들 복제하기 /// </summary> /// <param name="sourceProcessHandle">소스 프로세스 핸들</param> /// <param name="sourceHandle">소스 핸들</param> /// <param name="targetProcessHandle">타겟 프로세스 핸들</param> /// <param name="targetHandle">타겟 핸들</param> /// <param name="desiredAccess">희망 액세스</param> /// <param name="inheritHandle">핸들 상속 여부</param> /// <param name="option">옵션</param> /// <returns>처리 결과</returns> [DllImport("kernel32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool DuplicateHandle ( IntPtr sourceProcessHandle, IntPtr sourceHandle, IntPtr targetProcessHandle, ref IntPtr targetHandle, uint desiredAccess, [MarshalAs(UnmanagedType.Bool)] bool inheritHandle, uint option ); #endregion |