This article was previously published under Q187674
This article has been archived. It is offered "as is" and will no longer be updated.
This article demonstrates how to get the value of a constant required by aWindows API function call if the constant is undocumented in the API TextViewer. It shows how to declare this constant and value for use in VisualBasic. You can use this information to determine the value of a constant orverify that the values of the constants documented in the API Text Viewerare correct.
The API Text files that ship with Visual Basic document most of the APIconstants required by Visual Basic programmers. However, some API constantsare not documented in these text files. To look up the constants used byAPI functions, you will need the header files shipped in Visual Studio 97,Visual C++, or the Platform SDK.
The Platform SDK can be downloaded from the following site:
When you run the self-extracting file, the header files are expanded intothe \include directory.
These header files are the same ones used to create the DLL filescontaining the Windows API functions. This article assumes you are familiarwith using Visual Basic to access the functions in the Windows API.
To find this value, use the Advanced tab of the Find Files menu item in theStart menu of the Windows operating system. If you are using the ActiveDesktop that is included with Internet Explorer 4.0, specify the Name &Location tab. After finding the appropriate header file, open this headerfile in a text editor with search capabilities, such as the WordPad programthat ships with Windows.
Once you find the value of this constant, you declare it and its value inthe appropriate place in your Visual Basic code. Our example will declarethe constant in the General Declarations section of Form1.
For example, the function SHGetSpecialFoldersLocation returns the PIDLvalue of a specified special folder. To return the PIDL, the functionrequires the name of the special folder as one of the parameters. In ourexample, you want the PIDL value for the Drives special folders, which isdefined in the SHLOBJ.H header file as CSIDL_DRIVES.
To Find the Value of a Constant
From the Start menu, click Find and then Files & Folders. The Find: All Files dialog box appears.
In the Look in: text box, enter the path of the \include directory that contains all the header files.
Click the Advanced Tab. In the Containing Text field, type the name of the constant whose value you want. For Active Desktop users, the Containing Text field is in the first tab. In our example, type CSIDL_DRIVES.
Click Find Now. The file containing this constant is listed in that tab. In our example, CSIDL_DRIVES is in the SHLOBJ.H header file.
Open the specified file in a text editor, such as WordPad. Using the search capabilities of your text editor, search for the constant name. Our example uses Word Pad as the text editor:
From the Edit menu, click Find. The Find dialog box displays.
In the Find what: text box, type CSIDL_DRIVES.
Click Find Next.
The Find results shows the value of the constant CSIDL_DRIVES equal to 0x0011.
0x0011 is a hexadecimal number expressed in the syntax of C and C++. To use this number in Visual Basic, replace the leading '0x' with '&H'.
If a hexadecimal number is in the range of 0x8000 through 0xFFFF, add an ampersand (&) to the end of the hexadecimal constant. Adding an ampersand ensures that Visual Basic will not convert the constant value to a negative number. For example, if your constant is equal to 0x8000, convert this value for use in Visual Basic by declaring the constant equal to &H8000&:
Const MY_CONSTANT = &H8000&
If you do not add an ampersand to the end of the value, Visual Basic will evaluate the number as &HFFFF8000, or decimal -32768, rather than decimal 32768, as you might expect.
The following section illustrates how you can use this constant with yourVisual Basic project.
To Declare a Constant
Start a new Standard EXE project in Visual Basic. Form1 is created by default.
In the General Declarations section of Form1, type the following:
Const CSIDL_DRIVES = &H0011
Note that Visual Basic has automatically converted this value to the following:
Const CSIDL_DRIVES = &H11
The value of the constant CSIDL_DRIVES is now correctly declared in Visual Basic.