Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetTempPath()

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I'm trying to use the GetTempPath() API call, but am not having any luck...

Could someone inform me on how to call it from VB 6.0?

-Rob
 
This API and some others (GetUserName) do not return the value that you're after, but rather, populate a parameter by reference with the appropriate information, provided that it can.

First declare the function prototype in a module

Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

The in your code, declare and initialize the parameter to accept the returning information.

Dim lStr_TempPath as String
' Initialize the buffer to all nulls, with a max length of 254 chars
lStr_TempPath = String (254, chr(0))
' Call the API with the appropriate parameters note the match in length
GetTempPath 254, lStr_TempPath
' Since C null terminates strings, but VB does not, we need to remove the balance of the trailing nulls
lStr_TempPath = left(lStr_TempPath, InStr(lStr_TempPath, chr(0)) - 1) Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
For alternative methods of obtaining this same information, you might want to take a look at the GetSpecialFolder method of the FileSystemObject, and I also belive that you can find this information in the SpecialFolders collection, a property of the IWshRuntimeLibrary.IWshShell_Class, which can accessed by including a reference to the Windows Script Host Object Model into the project. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
i posted some code in this thread that may help

thread222-436160
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top