Using WTL in an ATL Attributed Component

by Codewiz51 January 23, 2009 20:21

I like programming with WTL and ATL. It's straight forward, clean and quite frankly, simple. I've worked a little with attributed ATL projects and attributes make certain functions a lot simpler.

I needed to recode an ActiveX component recently to work around Vista's IE protected mode. I decided to work with attribtued ATL. Since several dialogs were involved, I decided to drag in WTL to simplify the dialog code. That's when the problems began.

I didn't know this, but attributed ATL projects drag in atlstr.h, via the header file atlplus.h. You need to define _WTL_NO_CSTRING before including atlmisc.h. Otherwise, your component will attempt to compile WTL::CString and ATL::CString. The results are "unpredictable", but generally not fun to resolve.

Here's a reference: WTL CString Class Implemented with the Standard C++ Library

I've reproduced the key items:

  1. WTL::CString is not compiled if you #define _WTL_NO_CSTRING before #include <atlmisc.h>
  2. You will get ATL::CString support if you #include <atlstr.h> before #include <atlapp.h>
  3. When ATL::CString is supported, WTL::CString should not be compiled.
  4. If rule 2 does not apply, you will get WTL::CString support for classes defined after #define _WTL_USE_CSTRING
  5. If rule 2 does not apply, you will get WTL::CString support for classes defined after #include <atlmisc.h>

 

Here's the order you need to use. Other headers should follow these four.

#define _WTL_NO_CSTRING

#include <atlbase.h>
#include <atlapp.h>
#include <atltypes.h>
#include <atlmisc.h>

Tags:

Comments

1/23/2009 9:56:59 PM #

I was struck by your comment that ATL was simple. I suppose you're right.  ATL can be daunting, but given the problem it solves, there is something simple about it.  It's certainly more transparent that wizard-generated MFC code.

John United States

Comments are closed

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen | Modified by Mooglegiant

Disclaimer

This blog represents my personal hobby, observations and views. It does not represent the views of my employer, clients, especially my wife, children, in-laws, clergy, the dog, the cats or my daughter's horse. In fact, I am not even sure it represents my views when I take the time to reread postings.

© Copyright 2008-2011