Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
Declare Function GetTempPath Lib "kernel32.dll" (nBufferLength As Integer, _
<Out> lpBuffer As StringBuilder) As Integer
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
VB Sample
'TempFile.vb
'(DllImport declarations omitted)
Public Class TempFile
Public Function Create(ByVal astrFoldername As String, _
ByVal astrPrefix As String) As String
Dim tempPath As New StringBuilder(MAX_PATH - 14)
Dim tempName As New StringBuilder(MAX_PATH)
Dim lngRet As Integer
Dim result As String = ""
lngRet = 1
If (astrFoldername = "") Then
lngRet = GetTempPath(MAX_PATH - 14, tempPath)
astrFoldername = tempPath.ToString
End If
If (lngRet > 0 And lngRet <= MAX_PATH - 14) Then
lngRet = GetTempFileName(astrFoldername, astrPrefix, 0, tempName)
If lngRet <> 0 Then
result = tempName.ToString
End If
End If
'''<summary>
'''This is a test class for TempFileTest and is intended
'''to contain all TempFileTest Unit Tests
'''</summary>
<TestClass()> _
Public Class TempFileTest
Private fFoldername As String = "C:\TempFile"
Private fPrefix As String = "Prefix" ' Only first three characters will be used by Windows API
Private testContextInstance As TestContext
'''<summary>
'''Gets or sets the test context which provides
'''information about and functionality for the current test run.
'''</summary>
Public Property TestContext() As TestContext
Get
Return testContextInstance
End Get
Set(ByVal value As TestContext)
testContextInstance = value
End Set
End Property
'''<summary>
'''A test for Create
'''</summary>
<TestMethod()> _
Public Sub CreateTest()
Dim target As TempFile = New TempFile
Dim expected As String = fFoldername + "\" + Left(fPrefix, 3) 'Only part of the expected answer. The other part is random.
Dim actual As String
Dim dirInfo As DirectoryInfo
If Not Directory.Exists(fFoldername) Then
dirInfo = Directory.CreateDirectory(fFoldername)
If Not dirInfo.Exists Then
Throw New Exception("Directory '" + fFoldername + "' can not be created")
End If
End If
actual = target.Create(fFoldername, fPrefix)
Assert.IsTrue(File.Exists(actual))
'Remove file before procedure exits.
File.Delete(actual)
Assert.AreEqual(Left(expected, Len(fFoldername) + 4), Left(actual, Len(fFoldername) + 4))
Dim shortPath As New StringBuilder(TempFile.MAX_PATH)
TempFile.GetShortPathName(Path.GetTempPath, shortPath, TempFile.MAX_PATH)
expected = shortPath.ToString + Left(fPrefix, 3) ' GetTempPath end with "\"
actual = target.Create("", fPrefix)
Assert.IsTrue(File.Exists(actual))
'Remove file before procedure exits.
File.Delete(actual)
Assert.AreEqual(Left(expected, Len(fFoldername) + 4), Left(actual, Len(fFoldername) + 4))
End Sub
End Class
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).