NetReceiveAssociateRequest Example for C++ 6.0 and later

void CDicomNetSink::OnNetReceiveAssociateRequest (long hNet, long hPDU) 
{
   CString strMsg;
   int i;
   int nId;
   int nResult;
   _bstr_t strAbstract;
   _bstr_t strTransfer;

   //we have received an AssociateRequest

   strMsg = "*** NetReceiveAssociateRequest Event ***\n";
    
    //check the version, if not 1, reject it
    if (m_pDlg->m_pLEADDicomNet->GetVersion (hPDU) != 1)
    {
        m_pDlg->m_pLEADDicomNet->SendAssociateReject (hNet, 
                                       PDU_REJECT_RESULT_PERMANENT, 
                                       PDU_REJECT_SOURCE_USER, 
                                       PDU_REJECT_REASON_UNKNOWN
                                       );
        strMsg = strMsg + "SendAssociateReject\n";
    }
    else
    {
        //send associate accept class back
        m_pDlg->m_pLEADDicomNet->CreateAssociate (FALSE);
        m_pDlg->m_pLEADDicomNet->ResetAssociate (m_pDlg->m_pLEADDicomNet->GethPDU(), FALSE);

        //copy all presentation objects from received hPDU
        //reply that we only support the first Transfer Syntax from the received hPDU
        for (i = 0; i<m_pDlg->m_pLEADDicomNet->GetPresentationCount (hPDU); i++)
        {
            nId = m_pDlg->m_pLEADDicomNet->GetPresentationID (hPDU, i);
            strTransfer = m_pDlg->m_pLEADDicomNet->GetTransferSyntax(hPDU, nId, 0);
            nResult = PDU_ACCEPT_RESULT_SUCCESS;
            strAbstract = m_pDlg->m_pLEADDicomNet->GetPresentationAbstract (hPDU, nId);
            m_pDlg->m_pLEADDicomNet->AddPresentation (m_pDlg->m_pLEADDicomNet->GethPDU(), nId, nResult, strAbstract);
            m_pDlg->m_pLEADDicomNet->AddTransferSyntax (m_pDlg->m_pLEADDicomNet->GethPDU(), nId, strTransfer);
        }
        m_pDlg->m_pLEADDicomNet->SendAssociateAccept(hNet);
        strMsg = strMsg + "SendAssociateAccept\n";
        m_pDlg->m_pLEADDicomNet->FreeAssociate (m_pDlg->m_pLEADDicomNet->GethPDU());
    }

   AfxMessageBox(strMsg);