Skip to content

A Short Primer on Developing C++ in Windows

2010 June 3
by Tedb0t

As I have been working on a new contract involving C++ development on Windows, I thought I’d share some of my findings that tripped me up initially. Leave a comment if you found it helpful or think of other questions!

  • There are two different programming languages, and concepts, at play on Windows: straight-up C++ and “managed” C++/CLI, which stands for “Common Language Infrastructure.”  You’ll know it’s managed C++ if you see things like
    Bitmap^ myBitmap = gcnew Bitmap;


    public ref class

    That single caret took me a while to even find given that it doesn’t exist (except as a bitwise operator) in C++!

    The idea of managed C++ is to create a kind of garbage collection system for C++ (gcnew stands for “garbage collected new”), so the heap can track pointers, which normal C++ definitely cannot do.  A good place to start is here and here.

  • For this gig I’ve been developing a managed DLL wrapper between plain C++ and C#.  There is a good tutorial, but Microsoft’s documentation just leaves out some really helpful tidbits, such as this: if you’re writing a managed DLL, anything tagged as “public” is automatically exposed to other managed executables.  It’s confusing because their plain DLL tutorial tells you to use the

    tag before exported classes/methods, but for a managed DLL you don’t have to.  More confusingly, the DUMPBIN tool will not show any exported methods, but you can use them anyway.  WTF?  Oh well.

  • Speaking of DUMPBIN, here’s an incredibly handy tool if you have to have anything to do with DLLs:
    Dependency Walker
  • The logging system I ended up using is log4net, which is working great after a bit of bumpiness (they had typos in their example config files!)
  • Visual Studio is capable of using special comments to generate documentation, like so:
    /// <summary>This method does this...</summary>

    But then what?  You can use VS itself to generate XML files from those tags but there are also various documentation generators that use them.  Sandcastle looks like the best thing to use but so far it’s simple not compatible with Visual Studio 2010 solutions.  >:-|

Related Posts:

Comments are closed.