已答复 API documentation

  • 2005年12月9日 8:07
     
     
    I've just downloaded Visual C++ Express Edition. I have a couple of questions.

    1) what is the difference between ".h" files and "lib" files?
    2) How do I find reference for the various classes that come with VC++ Express? (Like the Java API documentation for the classes that come with the language?

    Thanks in advance.

全部回复

  • 2005年12月9日 9:21
     
     
    oh i found the answer for the 2nd question. All the reference that is required is found in the Online help feature of VC++ Express Edition.

    Difference between ".h" files and "lib" files anyone?
  • 2005年12月9日 10:14
    版主
     
     
    .. files are used by the compiler. The .h files are used to introduce functions, classes and structures. Sometime they contain code too. They are essential to share declarations between source modules.

    .lib files are used by the linker. They share object code between modules. Usually you get a .h file to to get all declarations you can use with this lib file.
  • 2005年12月9日 10:20
    版主
     
     已答复
     desijays wrote:
    1) what is the difference between ".h" files and "lib" files?
    Header files (.h) contain C/C++ statements and are used as input to the compiler. 
    http://en.wikipedia.org/wiki/Header_files

    Library files (.lib) contain object code and are used as input to the linker.
    http://en.wikipedia.org/wiki/Library_%28computer_science%29

    Very simplistically, a header file can be used to provide the declaration of a function while the lib file can be used to provide the implementation of the function.  So, for example, a math.h file might describe an add function that takes two int parameters and returns an int result.


    int add (int val1, int val2);
     

    Using this declaration (via a #include <math.h> statement) the compiler knows enough to validate source code that invokes the method and can build the object code to call the method, but it doesn't have any implementation of the add method so it has an unresolved reference to 'add'.  

    The linker combines the output of the compiler with various library files (such as math.lib) to resolve these references and create an executable file, a program.  There's no requirement that the .h and .lib file names match.  In fact there's no need for there to be the same number of .h and .lib files.

    That's only a broad outline though.  Since the header file contains source statements you can do almost anything with a header file that you can do with any other C or C++ file.  Header files can also be used to provide definitions for functions (and classes and structures) that you will be implementing in your own .c or .cpp files.  Good coding practice suggests you separate declarations and definitions putting declarations in .h and the implementation in .c/.cpp files so the .h file can be used (included) in other .cpp files.

    Some number of language standard header and lib files are included with the compiler itself.  Most Microsoft Windows specific header and lib files are included in something called the Platform SDK.  If you look back at the Visual C++ Express download page you'll see that step 4. is Install the Platform SDK.  You probably want to do that if you haven't already.

    2) How do I find reference for the various classes that come with VC++ Express? (Like the Java API documentation for the classes that come with the language?
    One place to look is in the MSDN library (library in the sense of collection of books not library in the sense of a .lib file).

    Right now there are two online versions of the MSDN, the msdn2 version is probably the better fit for Visual Studio Express.  Remember though that this is the full MSDN and may include things that VC++ Express doesn't support.
    http://msdn2.microsoft.com/default.aspx

    Some people find they prefer using Google to find these definitions.  For example,to find the printf() description try the first hit in this search
    http://www.google.com/search?hl=en&q=printf+site%3Amsdn2.microsoft.com

    There is also MSDN Express Library 2005 included in the VC++ Express. 

    Finally, if you want a CD or DVD copy of the full MSDN you can buy an MSDN Library subscription (perhaps not a good fit with the free VC++ Express).
    http://msdn.microsoft.com/vstudio/howtobuy/Default.aspx
  • 2005年12月10日 9:26
     
     
    Thanks a lot. Very helpful. And the google technique was nice too. Ofcourse i used it to find help for other code as well.. :)