Converting a Win32 Application to ATL

In the midst of all this publicity writing ATL-based applications, you will find little in the way of documentation on porting your legacy Win32 applications to ATL. Hopefully, these steps will ease that migration path.

Migration Steps

  1. Include AtlBase.h file in StdAfx.h after AfxWin.h. This is to take advantage to declare a variable for CComModule. Because AtlWin.h file needs, _Module as variable of CComModule.
    #include <atlbase.h>
    #include <objbase.h>
    
    We have to keep extern because we are originally declaring variable in Application main file.
    extern CComModule _Module;
    
    Then include the remaining files which helps for an ATL Application. In the insert Object of ATL uses ATLHost.h which needs to compile atlcom.h as before.
    #include <atlwin.h>
    #include <atlcom.h>
    
  2. In the StdAfx.cpp, Include AtlImpl.cpp file.
  3. In the main Application file, add the following
    //originally declaring the CComModule variable
    CComModule _Module; 
    
    Then, Add the following two lines, which are required to activate ATL Object Wizard, when you choose Insert ATLObject from Insert Menu.
    BEGIN_OBJECT_MAP(ObjectMap)
    END_OBJECT_MAP()
    
  4. Initialize the CComModule variable with ObjectMap and with the current instance in the WinMain function
    _Module.Init(ObjectMap, hInstance);
    
  5. Add the <ProjectName>.idl file into the project and add the library related code:
    library TestLIB
    {
    }
    
  6. If you want to insert a dialog and want to show. Follow the above steps and declare the variable of ur dialog class and call DoModal with that variable (don't forget to include dlg header file).

Additional Notes

This code has been tested with and works fine with the Windows CE environment.

References and Acknowledgments

  • ATL Internals - Rector, Sells (My thanks to the Authors!)


Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds