TAPI ?

Programming, for all ages and all languages.
Post Reply
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

TAPI ?

Post by Sam111 »

Ok I have followed threw coding for sending a phone call thru my V.92 modem.

Code: Select all


#define _WIN32_WINNT 0x0400
#define WIN32 0
#include <Tapi3.h>
#include <Objbase.h>
#include <iostream>

int main()
{
printf("hello" );
	// Initialize COM.
HRESULT hr = CoInitializeEx( NULL , COINIT_MULTITHREADED );
if(hr != S_OK) 
{
printf("error occured in initializing com ... " ) ;
return 0 ;
}

// Create a TAPI entry point object.
ITTAPI *gpTapi;    // globally allocated 
hr = CoCreateInstance( CLSID_TAPI, NULL, CLSCTX_INPROC_SERVER, IID_ITTAPI, (LPVOID *)&gpTapi );
if(hr != S_OK) 
{
printf("error occured in creating tapi entry point ... " ) ;
return 0 ;
}

// Initialize TAPI.
hr = gpTapi->Initialize();
if(hr != S_OK)
{
printf("error occured in initializing tapi entry point ... " ) ;
return 0 ;	
}

IEnumAddress * pIEnumAddress;
ITAddress * pAddress;
ITMediaSupport * pMediaSupport;
VARIANT_BOOL bSupport ;
// Use the TAPI object to enumerate available addresses.
hr = gpTapi->EnumerateAddresses( &pIEnumAddress );
if(hr != S_OK)
{
	printf( "error in gpTapi ...." ) ;
	system("PAUSE") ;
}
printf("got here  " ) ;
system("PAUSE" ) ;
// Locate an address that can support the media type the application needs.
while ( S_OK == pIEnumAddress->Next(1, &pAddress, NULL) )
{
    // Determine the media support.
    hr = pAddress->QueryInterface(
         IID_ITMediaSupport,
         (void **)&pMediaSupport
         );
    if(hr != S_OK)
	{
     printf( " pAddress QueryInterface error .... ") ;
     system("PAUSE" ) ;
	}

    // In this example, the required media type is already known.
    // The application can also use the address object to
    // enumerate the media supported, then choose from there.
    hr = pMediaSupport->QueryMediaType(
         TAPIMEDIATYPE_AUDIO|TAPIMEDIATYPE_VIDEO,
         &bSupport
         );
    if(hr != S_OK)
	{
      printf("pMediaSupport error...") ;
	  system("PAUSE");
	}

    if (bSupport)
    {
        break;
    }
}
// pAddress is now a usable address.
system("PAUSE" ) ;


    // Specify the destination address.


//
//const OLECHAR * szAddressToCall = CA2W("5555555");
const wchar_t szAddressToCall[] = L"5555555";

long dwAddressType = 0;
long mediatype = 0;
// retrieved from a user interface.
ITBasicCallControl * pBasicCall ;
BSTR bstrAddressToCall = SysAllocString( szAddressToCall );
if( bstrAddressToCall == NULL )
{
printf( "BSTR is NUll ... " ) ;
system("PAUSE" ) ;
}

hr = pAddress->CreateCall(
    bstrAddressToCall,
    dwAddressType,
    mediatype ,
    &pBasicCall
 );
if( hr != S_OK )
{
printf("pAddress-> CreateCall error...") ;
system("PAUSE") ;
}

SysFreeString(bstrAddressToCall);

// Create the required terminals for this call.

    // See the Select a Terminal code example.

// pAddress is an ITAddress interface pointer.
// pBasicCall is an ITBasicCallControl interface pointer.

// Get the ITStreamControl interface.
//ITBasicCallControl * pBasicCall = 0;


ITStreamControl * pStreamControl;
hr = pBasicCall->QueryInterface(
        IID_ITStreamControl,
        (void **) &pStreamControl
        );
if( hr != S_OK )
{
[b]printf("error in pStreamControl ... ") ; // Problem is here it fails get the intialize the pStreamControl?[/b]
system("PAUSE") ;
}
system("PAUSE" ) ;
// Enumerate the streams and select 
// terminals onto them.
IEnumStream * pEnumStreams;
ITStream    * pStream;
system("PAUSE" ) ;
hr = pStreamControl->EnumerateStreams(&pEnumStreams);
// If ( hr != S_OK ) process the error here. 
system("PAUSE" ) ;
while ( S_OK == pEnumStreams->Next(1, &pStream, NULL) )
{
    // Get the media type and direction of this stream.
    long lMediaType;
    TERMINAL_DIRECTION  dir;
    hr = pStream->get_MediaType( &lMediaType );
    // If ( hr != S_OK ) process the error here. 
    hr = pStream->get_Direction( &dir );
    // If ( hr != S_OK ) process the error here. 

    // Create the default terminal for this media type and direction.
    //   If lMediaType == TAPIMEDIATYPE_VIDEO and
    //   dir == TD_RENDER, a dynamic video render terminal
    //   is required. Please see Incoming.cpp in 
    //   the samples section of the SDK. 
    // For all other terminals, get the default static terminal.
    ITTerminal * pTerminal;
    ITTerminalSupport * pTerminalSupport;
    hr = pAddress->QueryInterface( 
            IID_ITTerminalSupport, 
            (void **)&pTerminalSupport
         );
    // If ( hr != S_OK ) process the error here. 
    hr = pTerminalSupport->GetDefaultStaticTerminal(
            lMediaType,
            dir,
            &pTerminal
         );
    // If ( hr != S_OK ) process the error here. 
    // Select the terminal on the stream.
    hr = pStream->SelectTerminal(pTerminal);
    // If ( hr != S_OK ) process the error here.

}

// Make the connection.
pBasicCall->Connect( TRUE );


	return 0 ;

}

I am trying to code my V.92modem to dial a phone number
Here is the link on the msdn site that talks you thru the code
http://msdn.microsoft.com/en-us/library ... de_samples
just cann't get all the pieces to work. Any help would be great. It compiles and links fine however I get an access violation if I proceed between these lines in the code

Code: Select all

system("PAUSE" ) ;
// Enumerate the streams and select 
// terminals onto them.
IEnumStream * pEnumStreams;
ITStream    * pStream;
system("PAUSE" ) ;
hr = pStreamControl->EnumerateStreams(&pEnumStreams);
// If ( hr != S_OK ) process the error here. 
system("PAUSE" ) ;

So the real problem is the unablety to create/initialize the pStreamControl in my program???

If I can get this then the only other thing that can go wrong would be the TERMINAL part4 of the examples.

Curious though what the difference is in using connect or dial functions of ITBasicCallControl to place the phone call? Maybe I should be using dial to use it with V.92 modem and connect if I was useing H323 or SIP or VOIP app...etc.

Thanks again for any help
I know it is alot to look at.

Remember it is this

Code: Select all

hr = pBasicCall->QueryInterface(
        IID_ITStreamControl,
        (void **) &pStreamControl
        );
that makes the whole thing fail hr is not OK :(

Cann't establish what why it is not ok am I not seting the parameters correctly if so what do I use?

Note also that if you want to download and test it you will have to change the 5555555 to a vailed phone number. And I was in VS2005 studio , windows XP SP 2 with DirectX 2008 installed ....
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: TAPI ?

Post by Combuster »

What you're asking is a configuration interface for something that doesn't have that particular configuration.

In fact the code examples linked from your source of reference do something different between opening TAPI and the Connect(), with no reference to StreamControl at all...

[ link1 ] [ link2 ]
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: TAPI ?

Post by Sam111 »

On your second link

it say's
Before using this code example, you must perform the operations in Initialize TAPI and Select an Address.

Also, you must perform the operations illustrated in Select a Terminal following the call to ITAddress::CreateCall.
I looked and Initialize TAPI should be the same regardless
Select an Address I may have to modify to the correct mediatype ,...etc

I look more into that tommarow. I am just begaining to understand TAPI. Their must be something to set it up so that you use the V.92 modem to call people with.

Thanks for your post.

My major problem is that I don't fully understad the selecting an address , selecting s terminal yet?
Post Reply