Tuesday, July 31, 2007

RichEdit Common Mistake MFC Win32

 If you ever tried RichEdit control in Vc++ , may be at first use you will notice that your application may crash , or the dialog is not coming.  The problem is , the RichEdit module is not loaded to memory initially. We need to load it explicitly. IF you are using MFC there are functions like
AfxInitRichEdit2(); // RichEdit Version 2
and
AfxInitRichEdit();  // RichEdit version 1.
If you are doing pure win32 , just by loading the richedit2.dll to meory will solve the problems , like
LoadLibrary("c:\\WINDOWS\\system32\\riched20.dll"); // this is richedit version 2.also remember to unload the module with FreeLibrary function.
You need to call the approrpiate function (AfxInitRichEdit or LoadLibrary) before creating richedit. The best way is to call is  in the InitInstance in MFC , or winmain Win32.

2 comments:

Biju said...

Really informative one...
After adding RichEdit the same problem to me also..
 
Thank you KD

Hammad said...

I tried adding the AfxInitRichEdit2() but it still does not work. I tried adding the riched20.dll through project options but no success. I am using Vista SP1 and Visual Studio 2008 SP1. The rich edit control is 2.0. In my case the problem is the dialog never shows up without any error.