📄 enumtapi.c
字号:
MyPrintf("N, ");
// Any apps waiting for calls?
if (LineDevStatus.dwOpenMediaModes)
MyPrintf("Y, ");
else
MyPrintf("N, ");
}
// Track down the Service Provider that owns this line device.
lReturn = lineGetID(hLine, 0, 0, LINECALLSELECT_LINE,
(VARSTRING*)&SmallVarString, "tapi/providerid");
if (lReturn)
dwProviderID = HIWORD(lpLineDevCaps->dwPermanentLineID);
else
dwProviderID = SmallVarString.handle;
// Looking for: HIWORD(dwPermanentLineID) == dwPermanentProviderID
dwCount = lpLineProviderList->dwNumProviders;
while(dwCount--)
{
if (dwProviderID == lpLineProviderEntry[dwCount].dwPermanentProviderID)
{
MyPrintf("%s - ", (char *)
((BYTE *) lpLineProviderList +
lpLineProviderEntry[dwCount].dwProviderFilenameOffset));
dwCount = 1;
break;
}
}
if (dwCount != 1)
MyPrintf("%s - ", szProviderUnknown);
// Find the name of the line device
if ((lpLineDevCaps -> dwLineNameSize) &&
(lpLineDevCaps -> dwLineNameOffset) &&
(lpLineDevCaps -> dwStringFormat == STRINGFORMAT_ASCII))
{
TCHAR szName[512];
CopyMemory((PVOID) szName,
(PVOID) ((BYTE *) lpLineDevCaps + lpLineDevCaps -> dwLineNameOffset),
lpLineDevCaps->dwLineNameSize);
lpszLineName = szName;
if (lpszLineName[0] != '\0')
{
// In case the device name is not null terminated, add one.
// Bug in the TSP, but fixable here.
lpszLineName[lpLineDevCaps->dwLineNameSize] = '\0';
}
else // Line name started with a NULL.
lpszLineName = szLineNameEmpty;
}
else // DevCaps doesn't have a valid line name. Unnamed.
lpszLineName = szLineUnnamed;
MyPrintf("%s",lpszLineName);
{
BYTE Buff[1024];
LPVARSTRING pVarString = (LPVARSTRING) Buff;
LPTSTR pszPortName = (LPTSTR) (Buff +sizeof(VARSTRING));
pVarString->dwTotalSize = sizeof(Buff);
if ((0 == lineGetID(hLine, 0, 0, LINECALLSELECT_LINE, pVarString, TEXT("comm/datamodem/portname"))) &&
(*pszPortName != TEXT('\0')))
{
MyPrintf(TEXT(" - %s"), pszPortName);
}
}
MyPrintf("\n");
lineClose(hLine);
}
void PrintModemInfo(DWORD i)
{
LONG lRet;
HLINE hLine;
BYTE VarBuff[1024];
LPVARSTRING lpVarString = (LPVARSTRING) VarBuff;
LPTSTR pszOut = (LPTSTR) VarBuff; // Re-using the buffer
HANDLE hFile;
BYTE Buff[sizeof(COMMPROP) + sizeof(MODEMSETTINGS) + 4096] = {0};
USHORT dwSize = sizeof(Buff);
COMMPROP *pcp = (COMMPROP *) Buff;
PMODEMDEVCAPS pmdc = (PMODEMDEVCAPS) &pcp->wcProvChar;
lpVarString->dwTotalSize = sizeof(VarBuff);
// We have to open with OWNER on Win9x to get modem info.
// Not true on other platforms.
lRet = lineOpen(hLineApp, i, &hLine, 0x00010004,
0, 0, LINECALLPRIVILEGE_OWNER, LINEMEDIAMODE_DATAMODEM,
NULL);
if (lRet != 0)
{
MyPrintf(TEXT("Not a modem: lineOpen on device %lu failed with %s\r\n"), i, FormatLineError(lRet));
return;
}
// Fill the VARSTRING structure
lRet = lineGetID(hLine, 0, 0, LINECALLSELECT_LINE, lpVarString, TEXT("comm/datamodem"));
if (lRet != 0)
{
MyPrintf(TEXT("Not a modem: lineGetId on %lu failed with %s\r\n"), i, FormatLineError(lRet));
return;
}
hFile = *((LPHANDLE)((LPBYTE)lpVarString + lpVarString -> dwStringOffset));
// Initialize the structure
pcp->wPacketLength = dwSize;
pcp->dwProvSubType = PST_MODEM;
pcp->dwProvSpec1 = COMMPROP_INITIALIZED;
if (!GetCommProperties(hFile, pcp))
{
MyPrintf(TEXT("Not a modem: GetCommProperties on %lu failed with %s\r\n"), i, FormatError(GetLastError()));
return;
}
if (pcp->dwProvSubType != PST_MODEM)
{
MyPrintf(TEXT("Note a modem: COMMPROP.dwProvSubType != PST_MODEM on device %lu\r\n"), i);
return;
}
if (pmdc->dwModemManufacturerOffset && pmdc->dwModemManufacturerSize)
{
memcpy(VarBuff, (LPVOID)(((LPBYTE) pmdc) + pmdc->dwModemManufacturerOffset), pmdc->dwModemManufacturerSize);
pszOut[pmdc->dwModemManufacturerSize] = TEXT('\0');
// On NT, this string will probably be Unicode rather than ANSI
#ifndef UNICODE
if ((VarBuff[1] == 0) && (pmdc->dwModemManufacturerSize > 1))
{
// Convert from Unicode to ANSI
CHAR szAnsi[1024];
wcstombs(szAnsi, (wchar_t *) VarBuff, 1024);
lstrcpy(pszOut, szAnsi);
}
#endif
MyPrintf(TEXT("Device %lu is a modem, Manufacturer: %s\r\n"), i, pszOut);
}
else
MyPrintf(TEXT("Device %lu is probably a modem, MODEMDEVCAPS.dwModemManufacturer is empty\r\n"), i);
return;
}
void CALLBACK lineCallbackFunc(
DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
{
// Not used for anything.
}
// Turn a TAPI Line error into a printable string.
char * FormatLineError (long lError)
{
static LPSTR pszLineError[] =
{
"LINEERR No Error",
"LINEERR_ALLOCATED",
"LINEERR_BADDEVICEID",
"LINEERR_BEARERMODEUNAVAIL",
"LINEERR Unused constant, ERROR!!",
"LINEERR_CALLUNAVAIL",
"LINEERR_COMPLETIONOVERRUN",
"LINEERR_CONFERENCEFULL",
"LINEERR_DIALBILLING",
"LINEERR_DIALDIALTONE",
"LINEERR_DIALPROMPT",
"LINEERR_DIALQUIET",
"LINEERR_INCOMPATIBLEAPIVERSION",
"LINEERR_INCOMPATIBLEEXTVERSION",
"LINEERR_INIFILECORRUPT",
"LINEERR_INUSE",
"LINEERR_INVALADDRESS",
"LINEERR_INVALADDRESSID",
"LINEERR_INVALADDRESSMODE",
"LINEERR_INVALADDRESSSTATE",
"LINEERR_INVALAPPHANDLE",
"LINEERR_INVALAPPNAME",
"LINEERR_INVALBEARERMODE",
"LINEERR_INVALCALLCOMPLMODE",
"LINEERR_INVALCALLHANDLE",
"LINEERR_INVALCALLPARAMS",
"LINEERR_INVALCALLPRIVILEGE",
"LINEERR_INVALCALLSELECT",
"LINEERR_INVALCALLSTATE",
"LINEERR_INVALCALLSTATELIST",
"LINEERR_INVALCARD",
"LINEERR_INVALCOMPLETIONID",
"LINEERR_INVALCONFCALLHANDLE",
"LINEERR_INVALCONSULTCALLHANDLE",
"LINEERR_INVALCOUNTRYCODE",
"LINEERR_INVALDEVICECLASS",
"LINEERR_INVALDEVICEHANDLE",
"LINEERR_INVALDIALPARAMS",
"LINEERR_INVALDIGITLIST",
"LINEERR_INVALDIGITMODE",
"LINEERR_INVALDIGITS",
"LINEERR_INVALEXTVERSION",
"LINEERR_INVALGROUPID",
"LINEERR_INVALLINEHANDLE",
"LINEERR_INVALLINESTATE",
"LINEERR_INVALLOCATION",
"LINEERR_INVALMEDIALIST",
"LINEERR_INVALMEDIAMODE",
"LINEERR_INVALMESSAGEID",
"LINEERR Unused constant, ERROR!!",
"LINEERR_INVALPARAM",
"LINEERR_INVALPARKID",
"LINEERR_INVALPARKMODE",
"LINEERR_INVALPOINTER",
"LINEERR_INVALPRIVSELECT",
"LINEERR_INVALRATE",
"LINEERR_INVALREQUESTMODE",
"LINEERR_INVALTERMINALID",
"LINEERR_INVALTERMINALMODE",
"LINEERR_INVALTIMEOUT",
"LINEERR_INVALTONE",
"LINEERR_INVALTONELIST",
"LINEERR_INVALTONEMODE",
"LINEERR_INVALTRANSFERMODE",
"LINEERR_LINEMAPPERFAILED",
"LINEERR_NOCONFERENCE",
"LINEERR_NODEVICE",
"LINEERR_NODRIVER",
"LINEERR_NOMEM",
"LINEERR_NOREQUEST",
"LINEERR_NOTOWNER",
"LINEERR_NOTREGISTERED",
"LINEERR_OPERATIONFAILED",
"LINEERR_OPERATIONUNAVAIL",
"LINEERR_RATEUNAVAIL",
"LINEERR_RESOURCEUNAVAIL",
"LINEERR_REQUESTOVERRUN",
"LINEERR_STRUCTURETOOSMALL",
"LINEERR_TARGETNOTFOUND",
"LINEERR_TARGETSELF",
"LINEERR_UNINITIALIZED",
"LINEERR_USERUSERINFOTOOBIG",
"LINEERR_REINIT",
"LINEERR_ADDRESSBLOCKED",
"LINEERR_BILLINGREJECTED",
"LINEERR_INVALFEATURE",
"LINEERR_NOMULTIPLEINSTANCE"
};
_declspec(thread) static TCHAR szError[512];
DWORD dwError;
HMODULE hTapiUIMod = GetModuleHandle(TEXT("TAPIUI.DLL"));
if (hTapiUIMod)
{
dwError = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
(LPCVOID)hTapiUIMod, TAPIERROR_FORMATMESSAGE(lError),
0, szError, sizeof(szError)/sizeof(TCHAR), NULL);
if (dwError)
return szError;
}
// Strip off the high bit to make the error code positive.
dwError = (DWORD)lError & 0x7FFFFFFF;
if ((lError > 0) || (dwError > sizeof(pszLineError)/sizeof(pszLineError[0])))
{
wsprintf(szError, "Unknown TAPI error code: 0x%lx", lError);
return szError;
}
return pszLineError[dwError];
}
/*=== Printing routines =============================================================*/
#define MAX_PRINT_STRING 1024
//#define MSG_BOX_PRINT
#ifdef _DEBUG
#define MSG_DEBUG_PRINT
#endif
#define MSG_CONSOLE_PRINT
void __cdecl MyPrintf(LPCTSTR lpszFormat, ...)
{
_declspec(thread) static TCHAR szOutput[MAX_PRINT_STRING]; // max printable string length
va_list v1;
DWORD dwSize;
va_start(v1, lpszFormat);
dwSize = wvsprintf(szOutput, lpszFormat, v1);
#ifdef MSG_DEBUG_PRINT
OutputDebugString(szOutput);
#endif
#ifdef MSG_CONSOLE_PRINT
_tprintf(szOutput);
#endif
#ifdef MSG_BOX_PRINT
MessageBox(NULL, szOutput, "MyPrintf Output", MB_OK);
#endif
}
LPCTSTR FormatError(DWORD dwError)
{
_declspec(thread) static TCHAR szBuff[MAX_PRINT_STRING];
return FormatErrorBuffer(dwError, szBuff, MAX_PRINT_STRING);
}
LPCTSTR FormatErrorBuffer(DWORD dwError, LPTSTR lpszBuff, DWORD dwNumChars)
{
DWORD dwRetFM = 0;
dwRetFM = wsprintf(lpszBuff, TEXT("%lu - "), dwError);
dwRetFM = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0,
&lpszBuff[dwRetFM], dwNumChars - dwRetFM, NULL);
if (dwRetFM == 0)
{
wsprintf(lpszBuff, TEXT("FormatMessage failed on %lu with %lu"),
dwError, GetLastError());
}
return lpszBuff;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -