2007-11-07

Customization: Custom Visual C++ Wizard - Part I

As I told you earlier - I am using Microsoft Visual C++ 2005 Express Edition. Unfortunately, this version of Visual C++ has some limitations. One such limitation, is that you can not design custom project (or item) wizards with it and for it. However, a creative person such as me or you, might still figure out the way...

Yes, that is true. I know how to add wizards. I will try to make one such custom wizard and in the process of making it - I will post articles about what I'm doing.

So. What is the first thing you should do, when making a wizard? Personally, when I figured out how wizards work - I started making one. Planning is for pussies, right? Wrong! Plan every single thing in your wizard. It is very frustrating, when you have to start over and over again.

Ok, so let's start from the list of annoying things in the default (console project) wizard. Here is my list:

  1. The default Debug and Release configurations.
  2. Default settings in those Debug and Release configurations.
  3. Solution and project directory structure.
  4. Default generated code.
I'd be interested to see your lists (it might give me ideas), so please - feel free to leave a comment. Thanks! Now, let's proceed.

Here are the explanations of each item on my list:
  1. I always break down my projects into small libraries. When I start developing those libraries - I never know if I'll want static library (LIB) or shared library (DLL). Also, I don't know which run-times I'll want to use in my final application (they can also be static and shared). So, it would be great if I could have a project with both. It means, that I want to start with four configurations: Debug Static, Debug Shared, Release Static and Release Shared. It doesn't really matter what kind of project I'm making - I always want these configurations.
  2. Now, when I'm writing my code - I always set the warning level to the max (level 4). Whenever I create a project with the default project wizard - I spend 15 minutes or so going through Project settings. That is wrong! I want the wizard to set the correct values for me, so that I can create a project and start coding!
  3. This is the tricky one. By default, Visual Studio solutions and projects have this directory structure:
    [solution] - top level solution directory;
    • [config] - each solution configuration gets it's own output directory;
    • [project] - project directory;
      • [config] - each project configuration gets it's own intermediate directory;
      • [project].vcproj - project file;
      • *.cpp, *.h, *.rc and so on - source files are all in this directory as well;
    • [solution].sln - solution file.
    Am I the only one concerned about the fact that intermediate files are placed in the subdirectory of the source code directory? I mean, when you hit "Clean Solution" - VC++ never cleans all of the files. There is always something left in that directory. So if you want to create a source code package (for whatever purposes), you have to manually delete those files. And the binaries? They are placed in separate directories in the top-level solution directory. Let's summarize. Here's how I imagine the perfect solution directory structure:
    [solution] - top level solution directory;
    • bin - executables (EXE and DLL files);
    • lib - libraries (all LIB files - DLL export libraries and static libraries);
    • src - source directory;
      • [solution] - top level source directory (so that we can have includes like this: "[solution]/[project]/[file].h");
        • [project] - project directory;
          • [project].vcproj - project file;
          • *.cpp, *.h, *.rc and so on - source files are all in this directory as well;
        • *.h - some common configuration headers;
    • tmp - intermediate files;
      • [config] - each project configuration gets it's own directory;
        • [project] - each project gets it's own intermediate directory;
    • [solution].sln - solution file.
  4. Seriously, is there anyone who uses that default code? I talked to a few coders I know - they all say that they always check "Empty project"! The code is just wrong. It could be so much more useful. Anyway, we will make a wizard that will add a lot of useful code for us (it will be preprocessor macros, mostly).
So. I have defined what I don't like about the default wizard and I've defined how those things should be fixed (how they will work in my own custom wizard). This is it for today. The second part of the article series will follow shortly.

2 comments:

Paulius Maruška said...

Note that Visual C++ 2008 Express Edition is out, so this series of articles will actually be about that release and not the 2005 version.

Research Writer said...

Many institutions limit access to their online information. Making this information available will be an asset to all.
Custom Paper Writing