The information in this article applies to:
SUMMARY
For Visual Basic programmers unfamiliar with the Win32 API, making a file
name for a temporary file is often a matter of hard-coding some value and
hoping that the name does not conflict with an existing file. Fortunately,
there is a better way that requires very little code.
MORE INFORMATIONGetTempPathThe GetTempPath API function allows you to determine the path location of a system's temporary folder. It takes two parameters: the length of a fixed- length or pre-initialized string that will contain the path name, and the string itself. You must use either a fixed-length string, or a string initialized to a length that you believe will be long enough to contain the path information. This is to guarantee that Visual Basic allocates enough buffer space for Windows to return the information.GetTempPath returns the length of the path name measured in bytes, or 0 if an error occurs. If the return value is greater than the buffer size you specified, then no path information was written to the string. The declaration for GetTempPath is provided in the sample below. GetTempFileNameThe GetTempFileName API function is used to create a fully-qualified temporary file name at a given location. The function takes four parameters: the string containing the path for the file, a string containing a prefix used to start the unique file name, a unique number to construct the temp name, and, finally, a fixed-length or pre-initialized string used to return the fully qualified file name. Both the path and prefix strings are required and cannot be empty. The unique number can be 0 (NULL), in which case GetTempFileName creates a unique number based on the current system time.GetTempFileName returns the unique number used to create the file name, or returns 0 if an error occurs. The declaration for GetTempFileName is provided in the sample below. Step-by-Step Example
REFERENCES
For additional information, please see the following articles in the
Microsoft Knowledge Base:
Q190000 : HOWTO: Get Started Programming With the Windows API (LONG) (c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Richard R. Taylor, Microsoft Corporation.
Keywords : kbAPI kbKernBase kbSDKWin32 kbVBp kbVBp500 kbVBp600 kbGrpVB kbCodeSam |
Last Reviewed: January 5, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |