WinFax Pro and Delphi

Hello everyone,
I am just posting this message because I had so much problems trying to find
a good example of this in Delphi that I want to help other who may need to
do this.

So here is a sample of how you drive WinFax Pro using the COM object
described in the WinFax Pro 10 sdk

Here is how you send a fax

function TForm1.test:integer;
var oWinFax : OleVariant;
    res    : integer;
    bFail  : boolean;
begin

  Result := 0;
  try
    oWinFax := CreateOleObject('WinFax.SDKSend');
  except
    ShowMessage('Could not create a WinFax.SDKSend API object');
    Result := 1;
    bFail := TRUE;
    Exit;
  end;

  oWinFax.LeaveRunning;

  //step 1
  if oWinFax.SetUseCover(0) = 1 then
    ShowMessage('Could not setUseCover');
  if oWinFax.SetSubject('Ici un sujet') = 1 then
    ShowMessage('Could not set subject');
  if oWinFax.SetUseCreditCard(0) = 1 then
    ShowMessage('Could not setUseCreditCard');
  if oWinFax.SetDeleteAfterSend(0) = 1 then
    ShowMessage('Could not setDeleteAfterSend');
  if oWinFax.SetResolution(0) = 1 then
    ShowMessage('Could not set resolution');

  if oWinFax.EnableBillingCodeKeyWords(1) = 1 then
    ShowMessage('Could not EnableBillingCodeKeyWords');

  //step 2
  {Set the fax details in winfax}
  oWinFax.SetTo('My name');
  if oWinFax.SetCompany('') = 1 then
    ShowMessage('Could setCompany');
  if oWinFax.SetBillingCode('') = 1 then
    ShowMessage('Could setBillingCode');
  if oWinFax.SetKeywords('') = 1 then
    ShowMessage('Could setKeywords');

  (*if oWinFax.SetCountryCode('1') = 1 then
    ShowMessage('Could setCoundtryCode');
  if oWinFax.SetAreaCode('514') = 1 then
    ShowMessage('Could set area code');  *)
  if oWinFax.SetNumber('342-5294') = 1 then
    ShowMessage('Could not set number');

  //step 3
  if oWinFax.AddRecipient = 1 then
    ShowMessage('Could not add fax recipient');

  //step 4
  if oWinFax.AddAttachmentFile('c:\Image1.fxr') = 1 then
    ShowMessage('Could not add file');

  if oWinFax.ShowCallProgress(0) = 1 then
    ShowMessage('Could not ShowCallProgress');

  oWinFax.Send(0);

  res := oWinFax.GetLastError;
  if res <> 0 then
    showmessage(inttostr(res));

  if oWinFax.EnableBillingCodeKeyWords(0) = 1 then
    ShowMessage('Failed Set EnableBillingCode to 0');

  oWinFax.Done;
end;

and here is how you convert a bmp to the fxr format of WinFax Pro

procedure TForm1.Button2Click(Sender: TObject);
var oConverter : OleVariant;
    lz_Input  : AnsiString;
    lz_Output : AnsiString;

    begin
  try
    oConverter := CreateOleObject('WinFax.SDKFXConverter');
  except
    ShowMessage('Could not create converter object');
    exit;
  end;

  lz_Input  := 'c:\Image1.bmp';
  lz_Output := 'c:\Image1.fxr';

  oConverter.ConvertToFX( lz_Input, lz_Output);
end;

I hope this will help some of you.

Have fun!

Daniel.