Is MFC obsolete?
"Nope" Says Rajesh R Subramanian (MSMVP VC++) , He further state this :-
First off, .NET and C++ (I will say only C++ in this message. But, When I say C++, include the frameworks and libraries built on and around it - MFC, ATL, WTL, etc.,) are entirely two different things. They exist to solve different problem sets and they cater to different consumers.
During the old days, there was not much of anything more than C/C++. There was another language known as VB, which was catering to an entirely different mass of programmers. The drag-n-drop guys. VB was too easy to learn, someone quoted "as easy as falling a flight of stairs". But it had several drawbacks, which I won't be listing up here.
So, C/C++ was the prominent choice if you wanted to build high quality, efficient programs. Then MS started pushing more things towards the "VB guys", which was easier. .NET. Period. It introduced a lot of new features, which would be very difficult if you had to achieve that with C++.
So, the world witnessed a whole new array of fresh .NET programmers (programming became easy) and another mass of C++ guys shifted to .NET, even the "Big Dogs" of the C++ game (some of them being passionate towards technology, wanting to learn the new stuff, some other moved because .NET was easier to do and was the upcoming trend). With the days, .NET has grown to be a true giant, and is the choice for developing large scale business applications which usually involves networking, databases, client/servers, dynamic webpages, etc.
As you've come from .NET background, I don't have to explain you how good is .NET while dealing with these things. It is the absolute gun, and C++ is no rival. But don't forget it: What .NET can do, C++ CAN do, faster, with lesser dependencies and cripples, lesser resources. But the cost and time of production will increase logarithmically. The C++ guys are expensive!
When it boils down to system side programming (desktop application development, device drivers, writing new funky frameworks like - uh... .NET, etc.,), C++ is the absolute cannon.
And to talk about the opportunities, sadly the market for C++ devs are comparatively less (when compared to .NET), but is NOT DEAD, NOT OBSOLETE. And will never die.
[added] We, a lot of Visual C++ developers had been discussing this with MS that no significant amount of development was put by MS for the betterment of native language programmers. MS pretty much agreed on the point and gave us a very favorable reply (there's a lot of non-disclosure stuff that I cannot disclose here legally). They also released feature pack for Visual C++ 2008[^], which has improved the features of the MFC framework tremendously. MS has clearly stated that their next version of Visual Studio will bring in a host of improvements for the C++ developers. [/added]
Theese C++ guys are the true Gurus, true Geeks.
Deleting structure memory resulted in memory leak?
Recently at Codeproject, I encountered following problem:-
“I have structure and I have created pointer to a structure. It is giving me memory leak if I delete this pointer also. Please help me how can I delete this pointer. Find below the code.
struct DemoTreeData
{
DWORD m_obj_id;
RWCString* ptext;
};
DemoTreeData* pTreeData=new DemoTreeData;
pTreeData->m_obj_id = debug->GetData();
pTreeData->ptext = new RWCString(debug->GetMessage()); --- 1
delete pTreeData; -- 2
pTreeData=NULL;
Can I delete the pointer like above or we have to write the destructor for that? Please suggest me. Thanks.“
Answer:-
First have a look, why deletion of the structure object is leaking memory, see the marking 1, Developer is allocating the memory to the structure variable ptext using NEW (mean’s allocating memory at runtime), and in marking 2 we are deleting the structure object memory without deleting the ptext memory, which is resulting in memory loss/leak.
Actually, when you allocate the memory to structure, it allocates only 4 Bytes ( Memory allocated to pointer) to ptext object. When you delete the structure variable, it only deletes the 4 bytes allocated to the ptext object, not the memory allocated to it, which is resulting in memory leak.
How to solve it?
Either writes the destructor where you de-allocate the memory associated with ptext variable or manually delete the memory allocate to ptext variable before deleting the structure variable. Don’t forget to assign NULL to ptext variable after deleting the memory.
Creating Folder with compressed property!
Mr Alex Rozanski answered this question with ease, here what he replied :-
Use
DeviceIoControl()with theFSCTL_SET_COMPRESSIONcontrol code (documentation here).
How to reuse dialog resource in another project ?
Just reading wonderful answer from SandipG in CP forums, see what he replied on that!
1. Copy the RC file from which you want to reuse the dialog to new Project folder
2. Add the copied rc file to your new project.
3. It will show you warning that there can be only one rc active but just say "ok" on it.
4. Now I just open the resource view and drag the dialogs or resources that you want from copied rc file to the new projects file.
5. After you are done just remove the copied rc file from the project.
Some times these small tips, save you from lot of copy pasting!
Setting default value of key?
Generally, when ever we want to set data member of the registry key, we provide the data name and data value in the SetKeyValue api for setting up value, however for setting up the value for default value, you have to put the data member as blank and rest would be same.
CRegKey key;
if( key.Create(HKEY_CURRENT_USER,L"Software\\Visualcpp") == ERROR_SUCCESS)
{
if(key.SetKeyValue(L"",L"Org") == ERROR_SUCCESS)
AfxMessageBox(L"Successful in setting the Default value of key");}
Please see, CRegKey class need ATLBASE.H header file to be included in the project.