+// ----------------------------------------------------------------------------
+// wxRichEditModule
+// ----------------------------------------------------------------------------
+
+#if wxUSE_RICHEDIT
+
+bool wxRichEditModule::OnInit()
+{
+ // don't do anything - we will load it when needed
+ return TRUE;
+}
+
+void wxRichEditModule::OnExit()
+{
+ if ( ms_hRichEdit )
+ {
+ FreeLibrary(ms_hRichEdit);
+ }
+}
+
+/* static */
+bool wxRichEditModule::Load(int version)
+{
+ wxCHECK_MSG( version >= 1 && version <= 3, FALSE,
+ _T("incorrect richedit control version requested") );
+
+ if ( version <= ms_verRichEdit )
+ {
+ // we've already got this or better
+ return TRUE;
+ }
+
+ if ( ms_hRichEdit )
+ {
+ ::FreeLibrary(ms_hRichEdit);
+ }
+
+ // always try load riched20.dll first - like this we won't have to reload
+ // it later if we're first asked for RE 1 and then for RE 2 or 3
+ wxString dllname = _T("riched20.dll");
+ ms_hRichEdit = ::LoadLibrary(dllname);
+ ms_verRichEdit = 2; // no way to tell if it's 2 or 3, assume 2
+
+ if ( !ms_hRichEdit && (version == 1) )
+ {
+ // fall back to RE 1
+ dllname = _T("riched32.dll");
+ ms_hRichEdit = ::LoadLibrary(dllname);
+ ms_verRichEdit = 1;
+ }
+
+ if ( !ms_hRichEdit )
+ {
+ wxLogSysError(_("Could not load Rich Edit DLL '%s'"), dllname.c_str());
+
+ ms_verRichEdit = -1;
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+#endif // wxUSE_RICHEDIT
+