선언:

C#

[DllImport("kernel32")]
public static extern Int32 GetCurrentProcessId();


VB.NET

<DllImport("kernel32")> _
Public Shared Function GetCurrentProcessId() As Int32
End Function




사용 예제:

C#

using System;
using System.Runtime.InteropServices;

namespace ApiReference {
    class ApiExample {
        [DllImport("kernel32")]
        public static extern Int32 GetCurrentProcessId();
        
        public static void Main(string[] args) {
            Console.WriteLine("현재 프로세스의 식별자(PID)는 {0} 입니다."GetCurrentProcessId());                
            Console.ReadKey(true);
        }
    }
}


VB.NET

Imports System
Imports System.Runtime.InteropServices

Namespace ApiReference
    Class ApiExample
        <DllImport("kernel32")> _
        Public Shared Function GetCurrentProcessId() As Int32
        End Function

        Public Shared Sub Main(args As String())
            Console.WriteLine("현재 프로세스의 식별자(PID)는 {0} 입니다.", GetCurrentProcessId())
            Console.ReadKey(True)
        End Sub
    End Class
End Namespace




예제 실행 결과:




매개 변수 설명:

없음




API 설명:

이 API를 호출하는 프로세스의 식별자(PID)를 반환합니다.




참고:

GetCurrentProcessId (MSDN)




비고:

자가 프로세스를 대상으로 한 작업을 할 때, 이 API를 사용하여 프로세스의 핸들을 얻을 수도 있고, 핸들 값 대신 -1을 이용할 수도 있습니다.



'API Reference' 카테고리의 다른 글

27. AbortSystemShutdown  (0) 2014.10.08
26. InitiateSystemShutdown  (0) 2014.10.08
24. DebugActiveProcessStop  (0) 2014.10.06
23. SetWindowText  (0) 2014.10.06
22. GetWindowTextLength  (0) 2014.10.04

+ Recent posts