Migration from MFC to STL
-
Hello all, Could anyone please give me a efficient method and suggestions for the following. I have many classes already in my VC++ project, which were build on MFC. Meaning the data types were MFC based. like CByteArray, CString etc etc. Now I need to avoid the uses of MFC data types , and introduce STL data types. could you please give me an efficient and less time consuming method to migrate the same. For eg: shal I use my own classes to mimic MFC classes like CString. or correct each uses/mehtod of MFC classes wherver there is, and change with STL based methods.... I am a bit confuse. please suggest me thanks in advance Hrishi
-
Hello all, Could anyone please give me a efficient method and suggestions for the following. I have many classes already in my VC++ project, which were build on MFC. Meaning the data types were MFC based. like CByteArray, CString etc etc. Now I need to avoid the uses of MFC data types , and introduce STL data types. could you please give me an efficient and less time consuming method to migrate the same. For eg: shal I use my own classes to mimic MFC classes like CString. or correct each uses/mehtod of MFC classes wherver there is, and change with STL based methods.... I am a bit confuse. please suggest me thanks in advance Hrishi
Hi Hrishi,
hrishi321 wrote:
I have many classes already in my VC++ project, which were build on MFC. Meaning the data types were MFC based. like CByteArray, CString etc etc. Now I need to avoid the uses of MFC data types , and introduce STL data types.
As MFC internally uses its own collection and string classes, you will increase your code footprint, and keep dependancy on all MFC classes and data types. Anyhow you can use
CStdString
[^] as drop-in replacement forCString
, and you should write your ownCStdByteArray
etc.. based on STL collections and exposing the same interface as the matching MFC collections. It could be an interesting CodeProject article :) Good luck! ARWhen the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
-
Hello all, Could anyone please give me a efficient method and suggestions for the following. I have many classes already in my VC++ project, which were build on MFC. Meaning the data types were MFC based. like CByteArray, CString etc etc. Now I need to avoid the uses of MFC data types , and introduce STL data types. could you please give me an efficient and less time consuming method to migrate the same. For eg: shal I use my own classes to mimic MFC classes like CString. or correct each uses/mehtod of MFC classes wherver there is, and change with STL based methods.... I am a bit confuse. please suggest me thanks in advance Hrishi
There's A LOT that goes into writing a framework, so you certainly don't want to write your own replacement classes. Depending on how much of the project is MFC based, you may have issues trying to replace with only STL calls. Some concepts don't exactly translate well, for example, what is a CDialog (the base for creating dialogs in MFC)? Well, its a bunch of WinAPI calls that create windows, configure properties, and act as a container for code within the dialog. How would you replicate that with STL alone? You can, but its a lot of work, STL is not exactly a framework that comes equipped as an MFC replacement (or replacement for any type of framework for that matter).
-
Hi Hrishi,
hrishi321 wrote:
I have many classes already in my VC++ project, which were build on MFC. Meaning the data types were MFC based. like CByteArray, CString etc etc. Now I need to avoid the uses of MFC data types , and introduce STL data types.
As MFC internally uses its own collection and string classes, you will increase your code footprint, and keep dependancy on all MFC classes and data types. Anyhow you can use
CStdString
[^] as drop-in replacement forCString
, and you should write your ownCStdByteArray
etc.. based on STL collections and exposing the same interface as the matching MFC collections. It could be an interesting CodeProject article :) Good luck! ARWhen the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
Thank you so much for your kind suggestion. I already started my implementation. Thought I am sure, I will have small doubts on my path. As a starter, I am trying to implement the CBytearray, Could you please tell me, whether do I need to implement FreeExtra() method of MFC CBytearray, in my stl:: vector? . Is there any methods to mimic this? Or actually STL tales care of it own?
-
There's A LOT that goes into writing a framework, so you certainly don't want to write your own replacement classes. Depending on how much of the project is MFC based, you may have issues trying to replace with only STL calls. Some concepts don't exactly translate well, for example, what is a CDialog (the base for creating dialogs in MFC)? Well, its a bunch of WinAPI calls that create windows, configure properties, and act as a container for code within the dialog. How would you replicate that with STL alone? You can, but its a lot of work, STL is not exactly a framework that comes equipped as an MFC replacement (or replacement for any type of framework for that matter).
thanks for your suggestion. After doing a small research and checking the amount of use of the MFC types, I have decided to implement the MFC types, whichever are in my project, and of-course not all methods but eh necessary ones. :) I will have many doubts during this course of time, Hope to keep getting advices from you :) thanks hrishi
-
Thank you so much for your kind suggestion. I already started my implementation. Thought I am sure, I will have small doubts on my path. As a starter, I am trying to implement the CBytearray, Could you please tell me, whether do I need to implement FreeExtra() method of MFC CBytearray, in my stl:: vector? . Is there any methods to mimic this? Or actually STL tales care of it own?
Hi, If your compiler supports C++2011 (VC2010 or gcc 4.5)
std::vector::shrink_to_fit()
is the functional equivalent toCByteArray::FreeExtra().
If you are on C++2003 usev.reserve(v.size())
to achieve the same goal. cheers, ARWhen the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
-
Hello all, Could anyone please give me a efficient method and suggestions for the following. I have many classes already in my VC++ project, which were build on MFC. Meaning the data types were MFC based. like CByteArray, CString etc etc. Now I need to avoid the uses of MFC data types , and introduce STL data types. could you please give me an efficient and less time consuming method to migrate the same. For eg: shal I use my own classes to mimic MFC classes like CString. or correct each uses/mehtod of MFC classes wherver there is, and change with STL based methods.... I am a bit confuse. please suggest me thanks in advance Hrishi
Why do you want to do that! Horses for Courses. Do you also want to migrate from Exel to Word? Regards, :)
Bram van Kampen