How To Find Undocumented Constants Used by Windows API Functions

Article translations Article translations
Article ID: 187674 - View products that this article applies to.
This article was previously published under Q187674
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SUMMARY

This article demonstrates how to get the value of a constant required by a Windows API function call if the constant is undocumented in the API Text Viewer. It shows how to declare this constant and value for use in Visual Basic. You can use this information to determine the value of a constant or verify that the values of the constants documented in the API Text Viewer are correct.

MORE INFORMATION

The API Text files that ship with Visual Basic document most of the API constants required by Visual Basic programmers. However, some API constants are not documented in these text files. To look up the constants used by API 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:
http://msdn.microsoft.com/en-us/library/ms996457.aspx

When you run the self-extracting file, the header files are expanded into the \include directory.

These header files are the same ones used to create the DLL files containing the Windows API functions. This article assumes you are familiar with 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 the Start menu of the Windows operating system. If you are using the Active Desktop that is included with Internet Explorer 4.0, specify the Name & Location tab. After finding the appropriate header file, open this header file in a text editor with search capabilities, such as the WordPad program that ships with Windows.

Once you find the value of this constant, you declare it and its value in the appropriate place in your Visual Basic code. Our example will declare the constant in the General Declarations section of Form1.

For example, the function SHGetSpecialFoldersLocation returns the PIDL value of a specified special folder. To return the PIDL, the function requires the name of the special folder as one of the parameters. In our example, you want the PIDL value for the Drives special folders, which is defined 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 your Visual 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.

Properties

Article ID: 187674 - Last Review: February 23, 2014 - Revision: 3.2
APPLIES TO
  • 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
Keywords: 
kbnosurvey kbarchive kbhowto KB187674

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com