Problem Using ActiveX in DLLs

 

Hello all

I have written a dll to open an HTML email every time and save it as plain text to be useful to expert advisors. I use Mictosoft Word for opening html file and save it as plain text , here is a part of dll code:

ofstream Msg(Dest + "\\experts\\files\\MessageFile.htm",ios::out|ios::trunc);
L3 = L3.Mid(i);
L3.MakeUpper();
L3.Replace(" ","");
Msg<<(L3);
Msg.close();
Msg = NULL;
 
CString Symbol = "";
if (L.Find("EURUSD") != -1 || L.Find("EUR-USD") != -1) Symbol = Symbol + " EURUSD ";
if (L.Find("USDCHF") != -1 || L.Find("USD-CHF") != -1) Symbol = Symbol + " USDCHF ";
if (L.Find("GBPUSD") != -1 || L.Find("GBP-USD") != -1) Symbol = Symbol + " GBPUSD ";
 
COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR); //For optional args
_Application Word;
Word.CreateDispatch("Word.Application");
Word.SetVisible(true);
CString ad1 = Dest + "\\experts\\files\\MessageFile.htm";
COleVariant Format(short(7)); //For optional args
Documents DS= Word.GetDocuments();
_Document D=DS.Open(COleVariant(ad1), vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, Format, 
                    vOpt, vOpt, vOpt, vOpt, vOpt, vOpt);
 
Selection S=Word.GetSelection();
S.HomeKey(COleVariant((short)6),vOpt);
S.TypeText(FirstFile);
S.TypeParagraph();
S.TypeText(FileType);
S.TypeParagraph();
S.TypeText(Symbol);
S.TypeParagraph();
try
{
D.SaveAs(COleVariant(Dest + "\\experts\\files\\MessageFile. txt"), COleVariant((short)4), 
         vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, COleVariant((short)false), 
         vOpt, vOpt, vOpt);
}
catch(CException* e)
{
ProcessCorrect = false;
Log<<("Save failed, " + e->ReportError())<<"\n";
}
Word.Quit(COleVariant((short)false), vOpt, vOpt);

The code was working well for a while, but now without any reson(at least what I can see), code doesn't create an instance of microsoftword.

any Idea?