Trouble using WTL7.0 in a MFC project
-
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
-
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
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
-
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
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
-
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
Thanks for the info. John