How To Find Undocumented Constants Used by Windows API Functions

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

  1. From the Start menu, click Find and then Files & Folders. The Find: All Files dialog box appears.
  2. In the Look in: text box, enter the path of the \include directory that contains all the header files.
  3. 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.
  4. 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.
  5. 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:

    1. From the Edit menu, click Find. The Find dialog box displays.
    2. In the Find what: text box, type CSIDL_DRIVES.
    3. 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

  1. Start a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. 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.
kbDSupport kbDSD Grep kbVBp kbVBp500 kbAPI kbSDKWin32 kbVBp600

Article ID: 187674 - Last Review: 02/23/2014 01:09:37 - Revision: 3.2

Microsoft Visual Basic 5.0 Learning Edition, Microsoft Visual Basic 6.0 Learning Edition, Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition, Microsoft Visual Basic Enterprise Edition for Windows 6.0

  • kbnosurvey kbarchive kbhowto KB187674