선언:

C#

[DllImport("kernel32")]
public static extern Int32 GetTempPath(Int32 BufferLength, StringBuilder Buffer);


VB.NET

<DllImport("kernel32")> _
Public Shared Function GetTempPath(BufferLength As Int32, Buffer As StringBuilder) As Int32
End Function




사용 예제:

C#

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace ApiReference {
    class Program {
        [DllImport("kernel32")]
        public static extern Int32 GetTempPath(Int32 BufferLength, StringBuilder Buffer);
        
        public static void Main(string[] args) {
            StringBuilder sbTempPath = new StringBuilder(260);
            GetTempPath(260, sbTempPath);
            
            Console.WriteLine("임시 폴더 위치: ");
            Console.WriteLine("  {0}", sbTempPath);

            Console.ReadKey(true);
        }
    }
}


VB.NET

Imports System
Imports System.Runtime.InteropServices
Imports System.Text

Namespace ApiReference
    Class Program
        <DllImport("kernel32")> _
        Public Shared Function GetTempPath(BufferLength As Int32, Buffer As StringBuilder) As Int32
        End Function

        Public Shared Sub Main(args As String())
            Dim sbTempPath As New StringBuilder(260)
            GetTempPath(260, sbTempPath)

            Console.WriteLine("임시 폴더 위치: ")
            Console.WriteLine("  {0}", sbTempPath)

            Console.ReadKey(True)
        End Sub
    End Class
End Namespace




예제 실행 결과:




매개 변수 설명:

BufferLength - 임시 폴더의 위치가 저장될 버퍼의 크기를 입력합니다.

Buffer - 임시 폴더의 위치가 저장될 버퍼를 입력합니다.




API 설명:

임시 폴더의 위치를 가져옵니다.




참고:

GetTempPath (MSDN)




비고:

이 API는 아래의 환경 변수의 존재 유무를 확인하고 가장 먼저 나타나는 값을 반환합니다.

TMP (%TMP%)

TEMP (%TEMP%)

USERPROFILE (%USERPROFILE%)

윈도우즈 폴더 (%WINDIR%)

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

43. GetFileAttributes  (0) 2014.11.06
42. FileAttributes  (0) 2014.11.05
40. PROCESS_BASIC_INFORMATION  (0) 2014.10.31
39. GetLocalTime  (0) 2014.10.30
38. GetSystemTime  (0) 2014.10.30

+ Recent posts