Stuart McLachlan
stuart at lexacorp.com.pg
Tue Aug 16 08:21:44 CDT 2011
It's many years since I actually looked at that function.. I just keep in in a utility module that I has grown over time. You're correct, using the return value from the API call saves looking for the terminating null. I've simplified the function in my toolbox to: Public Function TempDir() As String Dim strPath As String Dim lngRetval As Long strPath = Space(MAX_PATH) lngRetval = GetTempPath(MAX_PATH, strPath) TempDir = Left(strPath, lngRetval) End Function On 16 Aug 2011 at 15:02, Gustav Brock wrote: > Hi Dale > > Here is a similar function, a bit more straight forward: > > <code> > ' > ---------------------------------------------------------------------- > --- ' Declarations for GetTempDirectory. > > Private Declare Function GetTempPath Lib "kernel32" Alias > "GetTempPathA" ( _ > ByVal nBufferLength As Long, _ > ByVal lpBuffer As String) As Long > > Public Function GetTempDirectory() As String > > ' Returns path to temp directory incl. traling backslash: > ' c:\winnt\temp\ > ' 2002-05-31. Cactus Data ApS, CPH. > > Const clngBufferLen As Long = 255 > Dim lngPath As Long > Dim strBuffer As String * clngBufferLen > > ' No special error handling. > On Error Resume Next > > lngPath = GetTempPath(clngBufferLen, strBuffer) > If lngPath < 0 Then > lngPath = 0 > End If > > GetTempDirectory = LCase(Left(strBuffer, lngPath)) > > End Function > </code> > > /gustav > > > >>> dkalsow at yahoo.com 16-08-2011 14:39 >>> > OK - thanks, One question how and is MAX_PATH defined? > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com >