📄 acdclnt.c
字号:
// allocate an array to hold the selected item's indexes
pItems = (LPINT)GlobalAlloc(GPTR, sizeof(int) * dwCount);
// get the item's indexes
SendDlgItemMessage(hwnd,
IDC_GROUPS,
LB_GETSELITEMS,
(WPARAM)dwCount,
(LPARAM)pItems);
// alloc a LINEAGENTGROUP array for groups
pNewLAG = (LPLINEAGENTGROUPLIST)GlobalAlloc(GPTR,
sizeof(LINEAGENTGROUPLIST) +
dwCount * sizeof(LINEAGENTGROUPENTRY));
// fill in sizes
pNewLAG->dwTotalSize = sizeof(LINEAGENTGROUPLIST) + dwCount * sizeof(LINEAGENTGROUPENTRY);
pNewLAG->dwUsedSize = pNewLAG->dwTotalSize;
pNewLAG->dwNeededSize = pNewLAG->dwTotalSize;
pNewLAG->dwListSize = sizeof(LINEAGENTGROUPENTRY) * dwCount;
pNewLAG->dwListOffset = sizeof(LINEAGENTGROUPLIST);
// count
pNewLAG->dwNumEntries = dwCount;
// get pointer to first entry in array
pNewGroupEntry = (LPLINEAGENTGROUPENTRY)(((LPBYTE)pNewLAG) + pNewLAG->dwListOffset);
// loop though all selected item
while (dwCount)
{
// get the item data associated with the item. this data
// is a group entry struct
pGroupEntry = (LPLINEAGENTGROUPENTRY)SendDlgItemMessage(hwnd,
IDC_GROUPS,
LB_GETITEMDATA,
(WPARAM)pItems[dwCount-1],
0);
// copy the GroupID to the new array
CopyMemory(&pNewGroupEntry->GroupID,
&pGroupEntry->GroupID,
sizeof(pGroupEntry->GroupID));
// these fields are not used
pNewGroupEntry->dwNameSize = 0;
pNewGroupEntry->dwNameOffset = 0;
// next entry
pNewGroupEntry++;
dwCount--;
}
// now that we've created the AGENTGROUPLIST, set it
EnterCriticalSection(&csLineReply);
glResult = lineSetAgentGroup(ghLine,
dwAddress,
pNewLAG);
if (glResult < 0)
{
LeaveCriticalSection(&csLineReply);
//error
}
else if (WaitForLineReply())
{
//error
}
GlobalFree(pNewLAG);
// now get the current state
item = (DWORD)SendDlgItemMessage(hwnd,
IDC_STATE,
CB_GETCURSEL,
0,
0);
// get item data. this is the state flag
dwState = (DWORD)SendDlgItemMessage(hwnd,
IDC_STATE,
CB_GETITEMDATA,
(WPARAM)item,
0);
// same for next state
item = (DWORD)SendDlgItemMessage(hwnd,
IDC_NEXTSTATE,
CB_GETCURSEL,
0,
0);
dwNextState = (DWORD)SendDlgItemMessage(hwnd,
IDC_NEXTSTATE,
CB_GETITEMDATA,
(WPARAM)item,
0);
// set it
EnterCriticalSection(&csLineReply);
glResult = lineSetAgentState(ghLine,
dwAddress,
dwState,
dwNextState);
if (glResult < 0)
{
LeaveCriticalSection(&csLineReply);
//error
}
else if (WaitForLineReply())
{
//error
}
// get the activity selected
item = (DWORD)SendDlgItemMessage(hwnd,
IDC_ACTIVITY,
CB_GETCURSEL,
0,
0);
// get the item data. this is the activity ID
dwActivity = (DWORD)SendDlgItemMessage(hwnd,
IDC_ACTIVITY,
CB_GETITEMDATA,
(WPARAM)item,
0);
// set it
EnterCriticalSection(&csLineReply);
glResult = lineSetAgentActivity(ghLine,
dwAddress,
dwActivity);
if (glResult < 0)
{
LeaveCriticalSection(&csLineReply);
//error
}
else if (WaitForLineReply())
{
//error
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
//
// LRESULT WaitForLineReply()
//
// waiting for a line reply.
//
// 2 issues:
// - using global variables for line reply information. only recommended
// in the most simple situations
//
// - using completion ports to demonstrate the completion port mechanism.
// since this app has ui, the wait loop has a message loop and a sleep()!!
//
///////////////////////////////////////////////////////////////////////////////
LRESULT WaitForLineReply()
{
MSG msg;
gbReply = FALSE;
LeaveCriticalSection(&csLineReply);
while (!gbReply)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Sleep(5);
}
return glResult;
}
///////////////////////////////////////////////////////////////////////////////////
//
// LRESULT CALLBACK AgentStateDlgProc ()
//
// Dialog proc for the agent status dialog
//
///////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK AgentStateDlgProc (HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
static DWORD dwAddress;
static LPLINEAGENTGROUPLIST pLAG;
switch (uMsg)
{
case WM_INITDIALOG:
dwAddress = (DWORD)lParam;
InitAgentDlg(hwnd,
dwAddress,
&pLAG);
SetFocus(GetDlgItem(hwnd,
IDC_GROUPS));
return 1;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
SaveAgentStatus(hwnd,
dwAddress);
GlobalFree(pLAG);
EndDialog(hwnd,
1);
return 1;
}
if (LOWORD(wParam) == IDCANCEL)
{
GlobalFree(pLAG);
EndDialog(hwnd,
1);
return 1;
}
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////
//
// **************TAPI WRAPPER FUNCTIONS**************
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// LineGetAgentGroupList()
//
///////////////////////////////////////////////////////////////////////////////
LINEAGENTGROUPLIST * LineGetAgentGroupList (HLINE hLine,
DWORD dwAddressID)
{
LINEAGENTGROUPLIST * pLineAgentGroupList;
static DWORD dwMaxNeededSize = sizeof(LINEAGENTGROUPLIST);
// Allocate an initial block of memory for the LINEAGENTGROUPLIST structure,
// which may or may not be big enough to hold all of the information.
//
pLineAgentGroupList = GlobalAlloc(GPTR, dwMaxNeededSize);
while (TRUE)
{
BOOL bError = FALSE;
if (pLineAgentGroupList == NULL)
{
return NULL;
}
pLineAgentGroupList->dwTotalSize = dwMaxNeededSize;
// Try (or retry) to get the LINEAGENTGROUPLIST information
//
EnterCriticalSection(&csLineReply);
glResult = lineGetAgentGroupList(hLine,
dwAddressID,
pLineAgentGroupList);
if (glResult < 0)
{
LeaveCriticalSection(&csLineReply);
bError = TRUE;
//error
}
else if (WaitForLineReply())
{
bError = TRUE;
//error
}
if (bError)
{
GlobalFree((HLOCAL)pLineAgentGroupList);
return NULL;
}
// If the currently allocated LINEAGENTGROUPLIST memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pLineAgentGroupList->dwNeededSize <= dwMaxNeededSize)
{
return pLineAgentGroupList;
}
else
{
dwMaxNeededSize = pLineAgentGroupList->dwNeededSize;
pLineAgentGroupList = GlobalReAlloc((HLOCAL)pLineAgentGroupList,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetAgentStatus()
//
///////////////////////////////////////////////////////////////////////////////
LINEAGENTSTATUS * LineGetAgentStatus (HLINE hLine,
DWORD dwAddressID)
{
LINEAGENTSTATUS * pLineAgentStatus;
static DWORD dwMaxNeededSize = sizeof(LINEAGENTSTATUS);
// Allocate an initial block of memory for the LINEAGENTSTATUS structure,
// which may or may not be big enough to hold all of the information.
//
pLineAgentStatus = GlobalAlloc(GPTR, dwMaxNeededSize);
while (TRUE)
{
BOOL bError = FALSE;
if (pLineAgentStatus == NULL)
{
return NULL;
}
pLineAgentStatus->dwTotalSize = dwMaxNeededSize;
// Try (or retry) to get the LINEAGENTSTATUS information
//
EnterCriticalSection(&csLineReply);
glResult = lineGetAgentStatus(hLine,
dwAddressID,
pLineAgentStatus);
if (glResult < 0)
{
LeaveCriticalSection(&csLineReply);
bError = TRUE;
//error
}
else if (WaitForLineReply())
{
bError = TRUE;
//error
}
if (bError)
{
GlobalFree((HLOCAL)pLineAgentStatus);
return NULL;
}
// If the currently allocated LINEAGENTSTATUS memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pLineAgentStatus->dwNeededSize <= dwMaxNeededSize)
{
return pLineAgentStatus;
}
else
{
dwMaxNeededSize = pLineAgentStatus->dwNeededSize;
pLineAgentStatus = GlobalReAlloc((HLOCAL)pLineAgentStatus,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetAgentCaps()
//
///////////////////////////////////////////////////////////////////////////////
LINEAGENTCAPS * LineGetAgentCaps (HLINEAPP hLineApp,
DWORD dwDeviceID,
DWORD dwAddressID)
{
LINEAGENTCAPS * pLineAgentCaps;
static DWORD dwMaxNeededSize = sizeof(LINEAGENTCAPS);
// Allocate an initial block of memory for the LINEAGENTCAPS structure,
// which may or may not be big enough to hold all of the information.
//
pLineAgentCaps = GlobalAlloc(GPTR, dwMaxNeededSize);
while (TRUE)
{
BOOL bError = FALSE;
if (pLineAgentCaps == NULL)
{
return NULL;
}
pLineAgentCaps->dwTotalSize = dwMaxNeededSize;
// Try (or retry) to get the LINEAGENTCAPS information
//
EnterCriticalSection(&csLineReply);
glResult = lineGetAgentCaps(hLineApp,
dwDeviceID,
dwAddressID,
TAPI_CURRENT_VERSION,
pLineAgentCaps);
if (glResult < 0)
{
bError = TRUE;
LeaveCriticalSection(&csLineReply);
//error
}
else if (WaitForLineReply())
{
bError = TRUE;
//error
}
if (bError)
{
GlobalFree((HLOCAL)pLineAgentCaps);
return NULL;
}
// If the currently allocated LINEAGENTCAPS memory block was big
// enough, we're all done, else we need to realloc the memory block
// and try again.
//
if (pLineAgentCaps->dwNeededSize <= dwMaxNeededSize)
{
return pLineAgentCaps;
}
else
{
dwMaxNeededSize = pLineAgentCaps->dwNeededSize;
pLineAgentCaps = GlobalReAlloc((HLOCAL)pLineAgentCaps,
dwMaxNeededSize,
GMEM_MOVEABLE);
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// LineGetAgentActivityList()
//
///////////////////////////////////////////////////////////////////////////////
LPLINEAGENTACTIVITYLIST LineGetAgentActivityList (HLINE hLine,
DWORD dwDeviceID,
DWORD dwAddressID)
{
LINEAGENTACTIVITYLIST * pLineAgentActivityList;
static DWORD dwMaxNeededSize = sizeof(LINEAGENTACTIVITYLIST);
// Allocate an initial block of memory for the LINEAGENTACTIVITYLIST structure,
// which may or may not be big enough to hold all of the information.
//
pLineAgentActivityList = GlobalAlloc(GPTR, dwMaxNeededSize);
for (;;)
{
BOOL bError = FALSE;
if (pLineAgentActivityList == NULL)
{
return NULL;
}
pLineAgentActivityList->dwTotalSize = dwMaxNeededSize;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -