Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Trouble using WTL7.0 in a MFC project

Trouble using WTL7.0 in a MFC project

Scheduled Pinned Locked Moved ATL / WTL / STL
helpc++question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luedi
    wrote on last edited by
    #1

    Hi I wanted to deploy the CPrintPreviewWnd from the WTL in a MFC project, but got compiling errors due to wrong usage of the CPaintDC class in the WTL headers. The problem boils down to the fact, that a typedef'd class in a namespace does not honor the namespace. The following code is a demonstration of the problem. Compilation will fail with the following error error C2664: 'f' : cannot convert parameter 1 from 'char [6]' to 'int' class CPaintDC { public: void f (int i) {}; }; namespace WTL { template class CDCT { public: void f (char* i) {}; }; typedef CDCT CDC; class CPaintDC : public CDC { }; class Test { public: Test () { CPaintDC dc; dc.f ("world"); } }; }; What you can see from the code is, that the class CPaintDC is once declared in the global namespace (from MFC) and once in the WTL namespace. Both declarations of the class have a different signature for the function f (in the global namespace one int parameter, in the WTL namespace one char*). Then the CPaintDC is used in a new class, again in the namespace WTL. I expected the WTL::CPaintDC class to be used in this context, but I the compiling error tells me that the global class was used. Changing the local Variable to be of type WTL::CPaintDC doesn't help, since the problem is in the declaration of the class CPaintDC in the namespace WTL. Here the base class for the CPaintDC is taken from the global namespace, even if there is an appropriate type definition just infront the class. changing the declaration to read > class CPaintDC : public WTL::CDC or > class CPaintDC : public CDCT everything is ok. If there isn't any global class of the same name, as within the namespace, the namespace part of the code above will compile correctly. Is this a documented bug in the compiler, or did I miss something? I'm using the VisualStudio 6.0 with SP5. Any ideas? Dirk

    J 1 Reply Last reply
    0
    • L luedi

      Hi I wanted to deploy the CPrintPreviewWnd from the WTL in a MFC project, but got compiling errors due to wrong usage of the CPaintDC class in the WTL headers. The problem boils down to the fact, that a typedef'd class in a namespace does not honor the namespace. The following code is a demonstration of the problem. Compilation will fail with the following error error C2664: 'f' : cannot convert parameter 1 from 'char [6]' to 'int' class CPaintDC { public: void f (int i) {}; }; namespace WTL { template class CDCT { public: void f (char* i) {}; }; typedef CDCT CDC; class CPaintDC : public CDC { }; class Test { public: Test () { CPaintDC dc; dc.f ("world"); } }; }; What you can see from the code is, that the class CPaintDC is once declared in the global namespace (from MFC) and once in the WTL namespace. Both declarations of the class have a different signature for the function f (in the global namespace one int parameter, in the WTL namespace one char*). Then the CPaintDC is used in a new class, again in the namespace WTL. I expected the WTL::CPaintDC class to be used in this context, but I the compiling error tells me that the global class was used. Changing the local Variable to be of type WTL::CPaintDC doesn't help, since the problem is in the declaration of the class CPaintDC in the namespace WTL. Here the base class for the CPaintDC is taken from the global namespace, even if there is an appropriate type definition just infront the class. changing the declaration to read > class CPaintDC : public WTL::CDC or > class CPaintDC : public CDCT everything is ok. If there isn't any global class of the same name, as within the namespace, the namespace part of the code above will compile correctly. Is this a documented bug in the compiler, or did I miss something? I'm using the VisualStudio 6.0 with SP5. Any ideas? Dirk

      J Offline
      J Offline
      John M Drescher
      wrote on last edited by
      #2

      I do not believe WTL and MFC are made to coexist. WTL is kind of an addon to ATL that gives you some of the fucntionality that you miss from MFC. John

      L 1 Reply Last reply
      0
      • J John M Drescher

        I do not believe WTL and MFC are made to coexist. WTL is kind of an addon to ATL that gives you some of the fucntionality that you miss from MFC. John

        L Offline
        L Offline
        luedi
        wrote on last edited by
        #3

        I wanted to use only the PrintPreview Feature from the WTL. I think this can also be easily rewritten in MFC. But it was available for a fast test. After I rewrote the problematic line to read: class CPrintDC : public WTL::CDC { } I could compile my project and everything is running fine. I was more astonished, that the lookup for typedef is first done in the global namespace and then in the local namespace. I think this is more a question concerning the compiler. Thanks Dirk

        J 1 Reply Last reply
        0
        • L luedi

          I wanted to use only the PrintPreview Feature from the WTL. I think this can also be easily rewritten in MFC. But it was available for a fast test. After I rewrote the problematic line to read: class CPrintDC : public WTL::CDC { } I could compile my project and everything is running fine. I was more astonished, that the lookup for typedef is first done in the global namespace and then in the local namespace. I think this is more a question concerning the compiler. Thanks Dirk

          J Offline
          J Offline
          John M Drescher
          wrote on last edited by
          #4

          Thanks for the info. John

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups