Closing Outlook using a Delphi application

I am am writing an application that must shut down Outlook. I have use the
following code which finds all windows containing the words 'Microsoft
Outlook' and closes them.

This works OK except that there is still a process running called
mapisp32.exe. I need to kill this process to properly shut down Outlook, but
because it doesn't have a window I can't use the above method. I don't want
to use the TerminateApplication because it's dangerous. I would prefer to
properly call the Outlook Exit and Log Off procedure, but I don't know how
to and my research has turned up nothing so far. Has anyone got any ideas?

Regards,

Rudy Bake

The code as it is now...

function HWndGet( partialTitle: string ): hWnd;
var
  hWndTemp: hWnd;
  iLenText: Integer;
  cTitletemp: array [0..254] of Char;
  sTitleTemp: string;
begin
    hWndTemp := FindWindow(nil, nil);
    while hWndTemp <> 0  do
      begin
        iLenText := GetWindowText(hWndTemp, cTitletemp, 255);
        sTitleTemp :=  cTitletemp;
        sTitleTemp := UpperCase(copy( sTitleTemp, 1, iLenText));
        if sTitleTemp <> '' then ShowMessage(sTitleTemp);
        partialTitle := UpperCase( partialTitle );
        if pos( partialTitle, sTitleTemp ) <> 0 then
            break;
        hWndTemp := GetWindow(hWndTemp, GW_HWNDNEXT);
        end;
    result := hWndTemp;
end;

procedure TForm1.button1click(Sender: TObject);
var
  iHandle : hwnd;
begin
  iHandle := HWndGet('MICROSOFT OUTLOOK');
  while iHandle <> 0 do
  begin
    SendMessage(iHandle, Wm_Close, 0, 0);
    iHandle := HWndGet('MICROSOFT OUTLOOK');
  end;
end;