?? enumtapi.c
字號:
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (C) 1995 Microsoft Corporation. All Rights Reserved.
/*-------------------------------------------------*\
EnumTapi is a sample console app that enumerates all the devices
made available by TAPI and prints relavent information on each one.
Whether a line is actually capable of datamodem or automatedvoice
depends on what specific capabilities are used by a specific application.
The checks made by this sample are fairly generic, so there isn't a
guarentee that any specific app will work.
This app could be tailored to check the needs of any specific
application and would make a simple but usefull tech-support tool.
This app will only run with TAPI API Version 1.4 or later.
This means Windows 95, Windows NT 4.0 or later versions of TAPI.
\*-------------------------------------------------*/
#pragma comment(linker, "/subsystem:console")
#pragma comment(lib, "tapi32")
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
void __cdecl MyPrintf(LPCTSTR lpszFormat, ...);
LPCTSTR FormatError(DWORD dwError);
LPCTSTR FormatErrorBuffer(DWORD dwError, LPTSTR lpszBuff, DWORD dwNumChars);
BOOL WINAPI HandlerRoutine(DWORD dwCtrlType);
// This version doesn't exist, so it's a bad thing to do!
// You never know what you're going to get in future versions.
// Only done here because we're querying TAPI and not doing anything complex.
#define TAPI_MAX_VERSION 0x0FFF0FFF
// Make sure to compile TAPI.H so that we can use all functions
#define TAPI_CURRENT_VERSION TAPI_MAX_VERSION
#include <tapi.h>
// However, use version 1.4 as much as possible
#define TAPI_REAL_VERSION 0x00010004
#define TAPI_SUCCESS 0
// TAPI global variables.
HLINEAPP hLineApp;
DWORD dwNumDevs;
long lReturn;
typedef struct MySimpleVarString_tag
{
VARSTRING;
DWORD handle;
TCHAR szString[256];
} MYSIMPLEVARSTRING;
MYSIMPLEVARSTRING SmallVarString;
LINEDEVSTATUS LineDevStatus;
LPLINEDEVCAPS lpLineDevCaps = NULL;
LPLINEPROVIDERLIST lpLineProviderList = NULL;
LPLINEPROVIDERENTRY lpLineProviderEntry;
#define BIG_STRUCT_SIZE 4096
// message strings. These should probably be resources instead.
TCHAR szAppName[] = TEXT("EnumTapi");
TCHAR szLineUnavail[] = TEXT("Line Unavailable");
TCHAR szLineUnnamed[] = TEXT("Line Unnamed");
TCHAR szLineNameEmpty[] = TEXT("Line Name is Empty");
TCHAR szProviderUnknown[] = TEXT("Provider Unknown");
// Prototypes
void CALLBACK lineCallbackFunc(
DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);
void PrintTapiLines(DWORD dwDeviceID);
void PrintModemInfo(DWORD i);
char * FormatLineError (long lError);
DWORD dwTAPIVersion = TAPI_CURRENT_VERSION;
// Main entry point.
int main(int argc, char **argv)
{
DWORD i;
LINEINITIALIZEEXPARAMS li;
BOOL bModemInfo = FALSE;
if ((argc > 1) && (0 == lstrcmp(argv[1], "-m")))
bModemInfo = TRUE;
li.dwTotalSize = sizeof(li);
li.dwOptions = LINEINITIALIZEEXOPTION_USEHIDDENWINDOW;
lReturn = lineInitializeEx(&hLineApp, NULL, lineCallbackFunc, szAppName, &dwNumDevs, &dwTAPIVersion, &li);
if (lReturn != TAPI_SUCCESS)
{
dwTAPIVersion = 0x00010004;
lReturn = lineInitialize(&hLineApp, GetModuleHandle(NULL),
lineCallbackFunc, szAppName, &dwNumDevs);
}
if (lReturn != TAPI_SUCCESS)
{
MyPrintf("lineInitialize failed: %s.\n", FormatLineError(lReturn));
return 0;
}
MyPrintf("Installed TAPI Version is %lu.%lu\n", dwTAPIVersion>>16, dwTAPIVersion&0x0000FFFF);
lpLineDevCaps = LocalAlloc(LPTR, BIG_STRUCT_SIZE);
lpLineProviderList = LocalAlloc(LPTR, BIG_STRUCT_SIZE);
lpLineDevCaps -> dwTotalSize = BIG_STRUCT_SIZE;
lpLineProviderList-> dwTotalSize = BIG_STRUCT_SIZE;
LineDevStatus . dwTotalSize = sizeof(LineDevStatus);
SmallVarString . dwTotalSize = sizeof(SmallVarString);
// Get the Provider List so its possible to associate a line device
// with a specific service provider later.
while(TRUE)
{
lReturn = lineGetProviderList(dwTAPIVersion, lpLineProviderList);
if (lReturn)
{
MyPrintf("lineGetProviderList failed: %s\n", FormatLineError(lReturn));
break;
}
if (lpLineProviderList->dwNeededSize <= lpLineProviderList->dwTotalSize)
break; // Got it all
lpLineProviderList =
LocalReAlloc(lpLineProviderList,
lpLineProviderList->dwNeededSize, LMEM_MOVEABLE);
lpLineProviderList->dwTotalSize = lpLineProviderList->dwNeededSize;
}
lpLineProviderEntry = (LPLINEPROVIDERENTRY)
((BYTE *) lpLineProviderList +
lpLineProviderList->dwProviderListOffset);
MyPrintf(
"Installed TAPI Service Providers\n"
"<- dwPermanentProviderID\n"
" <- ProviderFilename\n");
for(i = 0; i < lpLineProviderList->dwNumProviders; i++)
{
MyPrintf("0x%08X %s\n", lpLineProviderEntry[i].dwPermanentProviderID,
(LPTSTR) lpLineProviderList + lpLineProviderEntry[i].dwProviderFilenameOffset);
}
if (dwNumDevs)
{
MyPrintf(
"\nInstalled TAPI line Devices\n"
"<- dwDeviceID\n"
"| <- Max dwAPIVersion\n"
"| | <- dwNumAddresses\n"
"| | | <- dwPermanentLineID\n"
"| | | | <- Capable of making voice comm/datamodem calls?\n"
"| | | | | <- Capable of making automated voice calls?\n"
"| | | | | | <- Call in progress?\n"
"| | | | | | | <- Any application waiting for calls?\n"
"| | | | | | | | <- Service Povider - Line Device Name\n"
"V V V V V V V V\n"
);
for (i=0;i<dwNumDevs;i++)
{
PrintTapiLines(i);
}
if (bModemInfo)
for (i = 0; i < dwNumDevs; i++)
{
PrintModemInfo(i);
}
}
else
MyPrintf("No TAPI Line devices installed.\n");
lineShutdown(hLineApp);
LocalFree(lpLineDevCaps);
LocalFree(lpLineProviderList);
return 1;
}
void PrintTapiLines(DWORD dwDeviceID)
{
BOOL bSupportsDataComm = TRUE;
BOOL bSupportsAutomatedVoice = TRUE;
DWORD dwApiVersion;
LINEEXTENSIONID ExtensionID;
HLINE hLine;
DWORD dwAddressID = 0;
char * lpszLineName;
DWORD dwCount;
DWORD dwProviderID;
MyPrintf("%-2lu, ", dwDeviceID);
// Find the max API Version supported.
// Note that this is normally a bad thing to do!!!
// Usually, you use an API Version that you know your app can support.
lReturn = lineNegotiateAPIVersion (hLineApp, dwDeviceID,
0x00010003, TAPI_MAX_VERSION, &dwApiVersion, &ExtensionID);
if (lReturn)
{
MyPrintf("lineNegotiateAPIVersion error: %s\n", FormatLineError(lReturn));
return;
}
MyPrintf("%lu.%lu, ", dwApiVersion>>16, dwApiVersion&0x0000FFFF);
while(TRUE)
{
lReturn = lineGetDevCaps(hLineApp, dwDeviceID,
dwApiVersion, 0, lpLineDevCaps);
if (lReturn)
{
MyPrintf("lineGetDevCaps error: %s\n", FormatLineError(lReturn));
return;
}
if (lpLineDevCaps->dwNeededSize > lpLineDevCaps->dwTotalSize)
{
lpLineDevCaps =
LocalReAlloc(lpLineDevCaps,
lpLineDevCaps->dwNeededSize, LMEM_MOVEABLE);
lpLineDevCaps->dwTotalSize = lpLineDevCaps->dwNeededSize;
continue;
}
break;
}
// Print number of available addresses..
MyPrintf("%lu, ", lpLineDevCaps->dwNumAddresses);
// Print permanent line ID
MyPrintf("0x%08lX, ", lpLineDevCaps->dwPermanentLineID);
// Check to see if basic data/voice capabilities are available.
if (!(lpLineDevCaps->dwBearerModes & LINEBEARERMODE_VOICE ))
bSupportsDataComm = FALSE;
if (!((lpLineDevCaps->dwBearerModes & LINEBEARERMODE_VOICE ) ||
(lpLineDevCaps->dwBearerModes & LINEBEARERMODE_SPEECH )))
bSupportsAutomatedVoice = FALSE;
if (!(lpLineDevCaps->dwMediaModes & LINEMEDIAMODE_DATAMODEM))
bSupportsDataComm = FALSE;
if (!(lpLineDevCaps->dwMediaModes & LINEMEDIAMODE_AUTOMATEDVOICE))
bSupportsAutomatedVoice = FALSE;
// Make sure it is possible to make a call.
if (!(lpLineDevCaps->dwLineFeatures & LINEFEATURE_MAKECALL))
{
bSupportsDataComm = FALSE;
bSupportsAutomatedVoice = FALSE;
}
// Have to open the line to check specific device classes.
lReturn = lineOpen(hLineApp, dwDeviceID, &hLine,
dwApiVersion, 0, 0, LINECALLPRIVILEGE_NONE, 0, 0);
if (lReturn)
{
MyPrintf("lineOpen error: %s\n", FormatLineError(lReturn));
return;
}
// Make sure the "comm/datamodem" device class is supported
lReturn = lineGetID(hLine, 0, 0, LINECALLSELECT_LINE,
(VARSTRING*)&SmallVarString, "comm/datamodem");
if (lReturn)
bSupportsDataComm = FALSE;
else
CloseHandle((HANDLE) SmallVarString.handle);
// Print the comm/datamodem results.
if (bSupportsDataComm)
MyPrintf("Y, ");
else
MyPrintf("N, ");
// Make sure both "wave/in" and "wave/out" device classes are supported.
lReturn = lineGetID(hLine, 0, 0, LINECALLSELECT_LINE,
(VARSTRING*)&SmallVarString, "wave/in");
if (lReturn)
bSupportsAutomatedVoice = FALSE;
else
{
lReturn = lineGetID(hLine, 0, 0, LINECALLSELECT_LINE,
(VARSTRING*)&SmallVarString, "wave/out");
if (lReturn)
bSupportsAutomatedVoice = FALSE;
}
// Print the automatedvoice results.
if (bSupportsAutomatedVoice)
MyPrintf("Y, ");
else
MyPrintf("N, ");
lReturn = lineGetLineDevStatus(hLine, &LineDevStatus);
if (lReturn)
{
MyPrintf("?, ?, ");
}
else
{
// Any calls in progress?
if (LineDevStatus.dwNumActiveCalls ||
LineDevStatus.dwNumOnHoldCalls ||
LineDevStatus.dwNumOnHoldPendCalls)
MyPrintf("Y, ");
else
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -