개체에 대한 기존 포인터 다시 사용
이 시나리오에서 서버는 매번 동일한 IAccessible 인터페이스 포인터를 사용하여 OBJID_CLIENT 요청에 응답합니다.
다음 예제 코드에서는 컨트롤 개체가 추가 창 데이터에서 검색되고, 액세스 가능성 서버 개체(애플리케이션에서 정의한 AccServer 클래스)를 검색하기 위해 컨트롤 메서드가 호출됩니다(있는 경우). 접근성 서버가 아직 없으면 만들어집니다.
접근성 서버 개체가 만들어지면 참조 개수는 1입니다. LresultFromObject 참조 수를 여러 번 증가시키지만, 클라이언트가 개체 작업이 완료되면 이러한 참조가 해제됩니다. 제어 창이 제거되면 서버에서 해당 참조를 해제합니다.
case WM_GETOBJECT:
{
// Return the IAccessible object.
if ((DWORD)lParam == (DWORD)OBJID_CLIENT)
{
// Get the control.
CustomListControl* pCustomList = (CustomListControl*)(LONG_PTR)GetWindowLongPtr(hwnd, 0);
// Create the accessible object.
AccServer* pAccServer = pCustomList->GetAccServer();
if (pAccServer == NULL)
{
pAccServer = new AccServer(hwnd, pCustomList);
pCustomList->SetAccServer(pAccServer);
}
if (pAccServer != NULL) // NULL if out of memory.
{
LRESULT Lresult = LresultFromObject(IID_IAccessible, wParam, pAccServer);
return Lresult;
}
else return 0;
}
break;
}
case WM_DESTROY:
{
CustomListControl* pCustomList = (CustomListControl*)(LONG_PTR)GetWindowLongPtr(hwnd, 0);
AccServer* pAccServer = pCustomList->GetAccServer();
if (pAccServer!= NULL)
{
// Notify the accessibility object that the control no longer exists.
pAccServer->SetControlIsAlive(false);
// Release the reference created in WM_GETOBJECT.
pAccServer->Release();
}
// Destroy the control.
delete pCustomList;
break;
}