i am trying to start a minor project on TAPI.
if you can help me to some good web resiource or post some basic project so that i can get started with it.
Thanks.
kunir
Michello
September 30th, 2003, 07:54 PM
Hello kunir,
enclosed some basic functions to make a call via TAPI.
First you have to initialize TAPI before any other TAPI function is called. If the following function succeeds, it returns a HLINEAPP handle that is the application's usage handle for TAPI, which should be defined as global. Further it return the number of available line devices to your application.
switch( dwReturn )
{
case LINEERR_REINIT:
// Try again later.
break;
// Handle other return values here.
}
return dwNumLineDevices;
}
An application should provide a callback function, in order to get some information about a line's state.
void TAPICallbackFunc( DWORD hDevice,
DWORD dwMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3 )
{
switch( dwMsg )
{
case LINE_CALLSTATE:
switch( dwParam1 )
{
case LINECALLSTATE_IDLE:
break;
case LINECALLSTATE_DIALTONE:
break;
case LINECALLSTATE_DIALING:
break;
case LINECALLSTATE_PROCEEDING:
break;
case LINECALLSTATE_RINGBACK:
break;
case LINECALLSTATE_CONNECTED:
break;
case LINECALLSTATE_BUSY:
break;
case LINECALLSTATE_DISCONNECTED:
switch( dwParam2 ):
{
case LINEDISCONNECTMODE_NORMAL:
break;
case LINEDISCONNECTMODE_UNKOWN:
break;
case LINEDISCONNECTMODE_REJECT:
break;
case LINEDISCONNECTMODE_BUSY:
break;
}
break;
default:
// Some other reason for disconnection.
}
break;
default:
// Some other notification.
}
}
When an application has finsihed using TAPI, a call to the following function should be made.
void ShutdownTAPI()
{
if( g_hLineApp )
{
lineShutdown( g_hLineApp );
g_hLineApp = NULL;
}
}
You need to negotiate the right version to ensure that all parties - the application, TAPI and the service provider DLL - agree on the version to use.
if( 0 != lineNegotiateAPIVersion( g_hLineApp,
dwLineId,
TAPI_VERSION_1_0, // Least recent API version.
TAPI_CURRENT_VERSION, // Most recent API version.
&dwTAPIVersion,
NULL ))
{
// The version could not be negotiated.
return 0;
}
return dwTAPIVersion;
}
In order to get detailled information about a certain line device, you need to pass a LINEDEVCAPS structure to the TAPI function lineGetDevCaps() - it further needs the negotiated TAPI version. The complexity in calling this function results from the LINEDEVCAPS structure - the size of the structure differs from line device to line device.
// Don't forget to free memory outside this function!
return true;
}
Now you're able to determine wether a certain line device is able to send or receive data or a fax, by checking the element dwLineMediaMode of the LINEDEVCAPS structure for the flag LINEMEDIAMODE_DATAMODEM or LINEMEDIAMODE_G3FAX.
Before you can do a call now, you first have to open a specified line. Do it like that.
if( 0 != lineOpen( g_hLineApp,
dwLineId,
&hLine,
dwTAPIVersion,
0,
0,
LINECALLPRIVILEGE_NONE, // Can only make an outgoing call.
0,
NULL ))
{
// Could not open line.
return NULL;
}
return hLine;
}
Well, before doing the call, a last step hast to be made: translating the phone number. This translation takes into account the configured current location of the user and determines if a local, long distance or international call needs to be made. It is even important, if you have a correctly formatted telephone number for the current location. Some line devices place a 'P' or 'T' before the telephone number to indicate pulse or tone dialing when translating the number, and without this call will fail. The needed structure LINETRANSLATEOUTPUT has again a variable size. So we have to proceed like above.
if( 0 > lineMakeCall( hLine,
&hCall,
szDialablePhoneNumber,
0, // This should be your country code.
NULL ))
{
// The call could not be made.
return NULL;
}
// Dialing asynchronously.
return hCall;
}
To be continued...
Michello
September 30th, 2003, 08:21 PM
Hello again...
Your main() could do something like this now (excuse the 'goto' ;-).
// Save the instance handle for global use.
g_hInstance = hInstance;
// Initialize TAPI and get number of available line devices.
if( !( dwNumLineDevices = InitializeTAPI() )
goto Exit;
for( dwLineId = 0; dwLineId < dwNumLineDevices; ++dwLineId )
{
// Negotiate TAPI version of the current line device.
if( !( dwTAPIVersion = NegotiateTAPIVersion( dwLineId )))
{
// Try the next line device.
continue;
}
// Search for the first datamodem.
if( GetLineDeviceCaps( dwLineId,
dwTAPIVersion,
pLineDeviceCaps ))
{
bDataModem = pLineDeviceCaps->dwLineMediaMode & LINEMEDIAMODE_DATAMODEM;
return 0;
}
I'm quite sure a lot of people are interested in using TAPI. That's why I did this small tutorial. Good luck!
kunir
October 1st, 2003, 04:11 PM
Hi Michello
thanx man for help, i have to submit a project next month and i was thinking of TAPI and i was searching through MSDN but didn't got much idea, thanx for the code.
let me try it, i will be posting a reply after trying it out.
Kunir
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.