📄 tapiinfo.c
字号:
if (!FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPTSTR) buf, sizeof(buf),
NULL))
{
wsprintf(szOutputBuffer, "Unknown error: %lu", GetLastError());
}
strcpy(szOutputBuffer, buf);
return szOutputBuffer;
}
// FUNCTION: FormatLineCallback(...)
//
// PURPOSE: Pretty prints into a buffer a lineCallbackFunc message.
//
// PARAMETERS:
// Standard lineCallbackFunc parameters.
//
// RETURN VALUE:
// The pointer to the buffer that has the resulting string.
//
// COMMENTS:
//
// This function takes all of the parameters passed into a
// lineCallbackFunc callback function, and pretty prints the
// meaning of the message. It then returns the pointer to
// the buffer containing this string.
//
// szOutputBuffer *must* be big enough to hold it all.
// 512 bytes is probably big enough.
//
LPSTR FormatLineCallback(
DWORD dwDevice, DWORD dwMsg, DWORD dwCallbackInstance,
DWORD dwParam1, DWORD dwParam2, DWORD dwParam3,
LPSTR szOutputBuffer)
{
long lBufferIndex = 0;
if (szOutputBuffer == NULL)
return NULL;
// Is this a known message?
if (dwMsg >= sizeofArray(psz_dwMsg))
{
wsprintf(szOutputBuffer, "Unknown dwMsg: '0x%lx', "
"dwDevice: '0x%lx', dwCallbackInstance: '0x%lx', "
"dwParam1: '0x%lx', dwParam2: '0x%lx', dwParam3: '0x%lx'", dwMsg,
dwDevice, dwCallbackInstance, dwParam1, dwParam2, dwParam3);
return szOutputBuffer;
}
// Lets start pretty printing.
lBufferIndex +=
wsprintf(szOutputBuffer, "%s; ", psz_dwMsg[dwMsg]);
// Which message was it? And start decoding it!
// How the message is decoded depends entirely on the message.
// READ THE HELP FILES if you need more information on this.
switch(dwMsg)
{
case LINE_ADDRESSSTATE:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"Address ID: 0x%lx, Address State: ", dwParam1);
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam2,
pszfLINEADDRESSSTATE, sizeofArray(pszfLINEADDRESSSTATE));
break;
}
case LINE_CALLINFO:
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam1,
pszfLINECALLINFOSTATE, sizeofArray(pszfLINECALLINFOSTATE));
break;
}
case LINE_CALLSTATE:
{
if (dwParam3)
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam3,
pszfLINECALLPRIVILEGE, sizeofArray(pszfLINECALLPRIVILEGE));
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"; ");
}
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam1,
pszfLINECALLSTATE, sizeofArray(pszfLINECALLSTATE));
switch(dwParam1)
{
case LINECALLSTATE_DIALTONE:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
": ");
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam2,
pszfLINEDIALTONEMODE, sizeofArray(pszfLINEDIALTONEMODE));
break;
}
case LINECALLSTATE_BUSY:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
": ");
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam2,
pszfLINEBUSYMODE, sizeofArray(pszfLINEBUSYMODE));
break;
}
case LINECALLSTATE_SPECIALINFO:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
": ");
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam2,
pszfLINESPECIALINFO, sizeofArray(pszfLINESPECIALINFO));
break;
}
case LINECALLSTATE_DISCONNECTED:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
": ");
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam2,
pszfLINEDISCONNECTED, sizeofArray(pszfLINEDISCONNECTED));
break;
}
case LINECALLSTATE_CONFERENCED:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
": Parent conference call handle: 0x%lx", dwParam2);
break;
}
}
break;
}
case LINE_CLOSE:
break;
case LINE_DEVSPECIFIC:
break;
case LINE_DEVSPECIFICFEATURE:
break;
case LINE_GATHERDIGITS:
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam1,
pszfLINEGATHERTERM, sizeofArray(pszfLINEGATHERTERM));
break;
}
case LINE_GENERATE:
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam1,
pszfLINEGENERATETERM, sizeofArray(pszfLINEGENERATETERM));
break;
}
case LINE_LINEDEVSTATE:
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam1,
pszfLINEDEVSTATE, sizeofArray(pszfLINEDEVSTATE));
switch(dwParam1)
{
case LINEDEVSTATE_RINGING:
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"; Ring Mode: 0x%lx, Ring Count: %lu"
,dwParam2, dwParam3);
break;
case LINEDEVSTATE_REINIT:
{
switch(dwParam2)
{
case LINE_CREATE:
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"; ReInit reason: LINE_CREATE, "
"New Line Device ID '0x%lx'"
, dwParam3);
break;
case LINE_LINEDEVSTATE:
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"; ReInit reason: LINE_LINEDEVSTATE, ");
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam3,
pszfLINEDEVSTATE, sizeofArray(pszfLINEDEVSTATE));
break;
case 0:
break;
default:
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"; ReInit reason: %s, dwParam3: 0x%lx"
,psz_dwMsg[dwParam2], dwParam3);
break;
}
break;
}
default:
break;
}
break;
}
case LINE_MONITORDIGITS:
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam2,
pszfLINEDIGITMODE, sizeofArray(pszfLINEDIGITMODE));
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
", Received: '%c'", LOBYTE(LOWORD(dwParam1)));
break;
}
case LINE_MONITORMEDIA:
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam1,
pszfLINEMEDIAMODE, sizeofArray(pszfLINEMEDIAMODE));
break;
}
case LINE_MONITORTONE:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"AppSpecific tone '%lu'", dwParam1);
break;
}
case LINE_REPLY:
{
if (dwParam2 == 0)
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"Request ID: 0x%lx; Successful reply!", dwParam1);
}
else
{
char szTmpBuff[64];
FormatTapiError((long) dwParam2, szTmpBuff);
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"Request ID: 0x%lx; UnSuccessful reply; %s",
dwParam1, szTmpBuff);
}
break;
}
case LINE_REQUEST:
{
lBufferIndex +=
strBinaryArrayAppend(&(szOutputBuffer[lBufferIndex]),
dwParam1,
pszfLINEREQUESTMODE, sizeofArray(pszfLINEREQUESTMODE));
switch(dwParam1)
{
case LINEREQUESTMODE_DROP:
{
char szHwndName[1024];
SendMessage((HWND) dwParam2, WM_GETTEXT, 1024, (long) szHwndName);
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
": hwnd dropping = 0x%lx, \"%s\"; wRequestID = %u",
dwParam2, szHwndName, LOWORD(dwParam3));
break;
}
default:
break;
}
break;
}
case LINE_CREATE:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"New Line Device ID '0x%lx'", dwParam1);
break;
}
case PHONE_CREATE:
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"New Phone Device ID '0x%lx'", dwParam1);
break;
}
default:
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"dwParam1: 0x%lx , dwParam2: 0x%lx , dwParam3: 0x%lx",
dwParam1, dwParam2, dwParam3);
break;
} // End switch(dwMsg)
// return that pointer!
return szOutputBuffer;
}
//
// FUNCTION: strBinaryArrayAppend(LPSTR, DWORD, LPSTR *, DWORD)
//
// PURPOSE: Takes a bitmapped DWORD, an array representing that
// binary mapping, and pretty prints it to a buffer.
//
// PARAMETERS:
// szOutputBuffer - Buffer to print to.
// dwFlags - Binary mapped flags to interpret.
// szStringArray - Array of strings.
// dwSizeofStringArray - number of elements in szStringArray.
//
// RETURN VALUE:
// The number of characters printed into szOutputBuffer.
//
// COMMENTS:
//
// This function takes dwFlags and checks each bit. If the
// bit is set, the appropriate string (taken from szStringArray)
// is printed to the szOutputBuffer string buffer. If there were
// more bits set in the string than elements in the array, and error
// is also tagged on the end.
//
// This function is intended to be used only within the TapiInfo module.
//
static long strBinaryArrayAppend(LPSTR szOutputBuffer, DWORD dwFlags,
LPSTR szStringArray[], DWORD dwSizeofStringArray)
{
DWORD dwIndex = 1, dwPower = 1;
long lBufferIndex = 0;
BOOL bFirst = TRUE;
// The zeroth element in every bitmapped array is the "unknown" or
// "unchanged" message.
if (dwFlags == 0)
{
lBufferIndex =
wsprintf(szOutputBuffer, "%s", szStringArray[0]);
return lBufferIndex;
}
// iterate through the flags and check each one.
while(dwIndex < dwSizeofStringArray)
{
// If we find one, print it.
if (dwFlags & dwPower)
// Seporate each printing with a ", " except the first one.
if (bFirst)
{
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"%s", szStringArray[dwIndex]);
bFirst = FALSE;
}
else
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
", %s", szStringArray[dwIndex]);
dwIndex ++;
dwFlags &= ~dwPower; // clear it so we know we checked it.
dwPower *= 2;
}
// If there are any flags left, they were not in the array.
if (dwFlags)
{
if (bFirst)
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
"Unknown flags '0x%lx'", dwFlags);
else
lBufferIndex +=
wsprintf(&(szOutputBuffer[lBufferIndex]),
", Unknown flags '0x%lx'", dwFlags);
}
// how many did we print into the buffer?
return lBufferIndex;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -