// TAPIDial.Cc
#include VdBase.H

CLASS TAPIDialer(formObj) of text(formObj) custom
/*======================================================================

Description:

Version: 1.0
Programmer: Bowen Moursund (bowen@nerds.com)
Date: 03/15/98
Written for: Visual dBASE 7.01

CLASS TAPIDialer is a simple VdB object wrapper of the TAPI
function tapiRequestMakeCall(). It's implemented as a VdB
custom control that can be installed on the Custom tab
of the VdB form designer.

CLASS TAPIDialer has but one public method:

   function Dial(<string cPhoneNumber>, <string cCalledParty>)

The cPhoneNumber parameter is required, and is the 'destination address'
in TAPI parlance.

The cCalledParty parameter is optional, and is the name or other
identifier of the called party. If DIALER.EXE is the default TAPI call
manager it will use this parameter when logging calls.

Open C:\WINDOWS\DIALER to configure it. Ensure that 'Use Phone dialer
to handle voice call requests from other programs' under
Tools|Connect Using is checked.

------------------------------------------------------------------------

Example of use:

   function DialButton_onClick
      form.TAPIDialer1.Dial(form.PhoneNoEntryfield.value,;
                            form.NameEntryfield.value)

======================================================================*/


   // visual properties for form designer
   with (this)
      height = 1.2
      width = 12
      border = true
      visible = false
      colorNormal = "black/yellow"
      alignVertical = 1	// Middle
      alignHorizontal = 1	// Center
      text = "TAPI Dialer"
      borderStyle = 4	// Single
   endwith

   protect Initialize
   function Initialize
      local lSuccess
      lSuccess = true
      if type("tapiRequestMakeCall") # "FP"
         try  // try, since TAPI32.DLL might not be installed
            extern CLONG tapiRequestMakeCall(CSTR, CSTR, CSTR, CSTR) ;
                   Tapi32.Dll
         catch (exception e)
            lSuccess = false
            AlertMessage(e.message,"Alert")
         endtry
      endif
      return lSuccess

   function Dial(cPhoneNumber,cCalledParty)
      if argC() = 0 or not class::Initialize()
         return
      elseif argC() = 1
         store "" to cCalledParty
      endif
      local lRequestSuccess
      // any return but 0 is an error
      lRequestSuccess = (tapiRequestMakeCall(cPhoneNumber, ;
                         "", cCalledParty, "") == 0)
      if not lRequestSuccess
         AlertMessage("Sorry, no TAPI call manager is available. " +;
                      "Ensure that DIALER.EXE is installed and " +;
                      "properly configured.","Alert")
      endif
      return lRequestSuccess

ENDCLASS

// EoF: TAPIDial.Cc
