locked
How to create a C++ class library?

    Question

  • First of all, in VS2011 under VC++, there is no option for a "Class Library", similar to the C# templates, which makes it seem like nobody would ever want to write a library in C++ anymore.  Why would a "Class Library" template not be available for VC++ projects?

    I went ahead and created a "WinRT Component DLL" project, in hopes that I can use it like a library.  According to the project properties, the Configuration Type is "Dynamic Library (.dll)", however after successfully compiling the project, I do not see any dll! I do see some *.obj files.  What am I missing here?

    I created another project, which is meant to be an executable (application) that utilizes the library, however there is no .lib to link against, so even though my include directories point to my library, I can't compile my project if I use the library.

    The reason for this design is to have a central library that implements basic game functionality, and an executable that uses this library and uses it to create an actual game.  Can anybody help me out here?

    Thursday, December 29, 2011 12:06 AM

Answers

  • Ben, Could you clarify what your trying to build? If your wanting a desktop (not a Metro style or WinRT component), then use VS 11 Ultimate as Ciger mentioned for either C++ or C# as you would in VS 2010.

     

    If you are attempting an similar architecture for Metro style apps, then a  C++ 'WinRT Component DLL' in VS 11 Express is the correct path for building a 'class library' that can be consumed from other Metro syle app projects. Here is a sample of a JavaScript app using a C++ WinRT Component:

    http://code.msdn.microsoft.com/windowsapps/Hybrid-JavaScript-and-C-e6dc77fa

     

    Thanks,

    -David

     


    Wednesday, January 04, 2012 1:34 AM
    Moderator

All replies

  • If you are using VS11 express, you might want to try this:

    http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27543

    VS 11 ultimate, in which you can find all legacy project types.

    Thursday, December 29, 2011 2:41 AM
  • Well if its a legacy project, what is the new method for creating a library in C++?

    Basically, you can create a "WinRT Component DLL" project, build it, and you won't see any dll or lib file.  This is what I'm seeing.

    Thursday, December 29, 2011 4:20 AM
  • I found that the .dll and .lib are being generated, but they were in a different directory.  oops!  Now I'm trying to figure out how to use the library.  Previously I used the __declspec keywords, but it looks like those do not work for "managed" classes.
    Thursday, December 29, 2011 9:46 PM
  • Ben, Could you clarify what your trying to build? If your wanting a desktop (not a Metro style or WinRT component), then use VS 11 Ultimate as Ciger mentioned for either C++ or C# as you would in VS 2010.

     

    If you are attempting an similar architecture for Metro style apps, then a  C++ 'WinRT Component DLL' in VS 11 Express is the correct path for building a 'class library' that can be consumed from other Metro syle app projects. Here is a sample of a JavaScript app using a C++ WinRT Component:

    http://code.msdn.microsoft.com/windowsapps/Hybrid-JavaScript-and-C-e6dc77fa

     

    Thanks,

    -David

     


    Wednesday, January 04, 2012 1:34 AM
    Moderator
  • I was trying to build a class library that can be used by Metro app projects.  Thanks for the help guys, I think for now I've decided to work on a native C++ class library using VS 2010.
    Wednesday, January 04, 2012 5:55 PM