선언:

C#

[DllImport("kernel32", CharSet = CharSet.Auto)]
public static extern Int32 GetSystemDirectory(String Buffer, Int32 BufferLength);


VB.NET

<DllImport("kernel32", CharSet := CharSet.Auto)> _
Public Shared Function GetSystemDirectory(Buffer As String, BufferLength As Int32) As Int32
End Function




사용 예제:

C#

using System;
using System.Runtime.InteropServices;

namespace ApiReference {
    class ApiExample {
        [DllImport("kernel32", CharSet = CharSet.Auto)]
        public static extern Int32 GetSystemDirectory(String Buffer, Int32 BufferLength);
        
        public static void Main(string[] args) {
            String sysDir = new string(' ', 260);
            GetSystemDirectory(sysDir, 260);
            sysDir = sysDir.Trim();
            Console.WriteLine("System Directory:");
            Console.WriteLine("  {0}", sysDir);
            Console.ReadKey(true);
        }
    }
}


VB.NET

Imports System
Imports System.Runtime.InteropServices

Namespace ApiReference
    Class ApiExample
        <DllImport("kernel32", CharSet := CharSet.Auto)> _
        Public Shared Function GetSystemDirectory(Buffer As String, BufferLength As Int32) As Int32
        End Function

        Public Shared Sub Main(args As String())
            Dim sysDir As String = New String(" "C, 260)
            GetSystemDirectory(sysDir, 260)
            sysDir = sysDir.Trim()
            Console.WriteLine("System Directory:")
            Console.WriteLine("  {0}", sysDir)
            Console.ReadKey(True)
        End Sub
    End Class
End Namespace




예제 실행 결과:




매개 변수 설명:

Buffer - 시스템 폴더의 경로가 저장될 변수를 입력합니다.

BufferLength - 시스템 폴더의 경로가 저장될 버퍼 변수의 길이를 입력합니다.




API 설명:

시스템 폴더의 경로를 가져옵니다.




참고:

GetSystemDirectory (MSDN)




비고:

API 호출 성공 시 버퍼에 복사된 크기를 반환합니다.



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

35. GetComputerName  (0) 2014.10.24
34. GetWindowsDirectory  (0) 2014.10.24
32. SendMessage  (1) 2014.10.11
31. SetWindowLong  (0) 2014.10.11
30. GetWindowLong  (0) 2014.10.10

+ Recent posts