Board index » delphi » Help I'm using code that I don't understand

Help I'm using code that I don't understand

I've parsed some code (full listing below) that I only partly understand.
What is the constant MK_E_UNAVAILABLE?  I've checked the help files on
OleCheck but I don't understand how this code works.  Can someone either
give me a brief explanation or point to some resources that explain what's
happening here:

if SCodeResult=MK_E_UNAVAILABLE then
      Outlook:=CoOutlookApplication.Create
    else
    begin
      OleCheck(SCodeResult);
      OleCheck(Unknown.QueryInterface(OutlookApplication,Outlook));
    end;

Thanks,
Bill N

//*************full listing*****************
function SendMail(SendTo:TStringList;Subject:string;Body:TStringList;
         AFile:string):boolean;
var Outlook:OutlookApplication;
    MI:MailItem;
    SCodeResult:HResult;
    Unknown:IUnknown;
    i,x:Byte;
const olMailItem=0;
begin
  Try
    Result:=True;
    SCodeResult:=GetActiveObject(CLASS_OutlookApplication,nil,Unknown);
    if SCodeResult=MK_E_UNAVAILABLE then
      Outlook:=CoOutlookApplication.Create
    else
    begin
      OleCheck(SCodeResult);
      OleCheck(Unknown.QueryInterface(OutlookApplication,Outlook));
    end;

    for i:=0 to SendTo.Count-1 do
    begin
      MI:=Outlook.createItem(olMailItem) as MailItem;
      MI.Body:='';
      MI.Recipients.Add(SendTo[i]);
      MI.Subject:=Subject;

      for x:=0 to Body.Count-1 do
        MI.Body:=MI.Body+ Body[x];

      MI.Attachments.Add(AFile,EmptyParam,EmptyParam,EmptyParam);
      MI.Send;
    end;
  except
    Result:=False;
  end;
end;

 

Re:Help I'm using code that I don't understand


MK_E_UNAVAILABLE means something like I couldn't get to a running instance
of an object/moniker. This HRESULT should be docoument on MSDN online.

OleCheck is a Delphi function that tests for the success status of a COM
HRESULT. If the HRESULT indicates failure, OleCheck will raise a proper
native Delphi exception. HRESULT is a COM standard used to return
status/failure codes from COM calls.

--
have fun
Binh Ly
www.techvanguards.com

Quote
"Bill_N" <a_fam...@telusplanet.net> wrote in message

news:3afb2a61$1_2@dnews...
Quote
> I've parsed some code (full listing below) that I only partly understand.
> What is the constant MK_E_UNAVAILABLE?  I've checked the help files on
> OleCheck but I don't understand how this code works.  Can someone either
> give me a brief explanation or point to some resources that explain what's
> happening here:

Other Threads