GetUserInfoCount Example for C++ 6.0 and later
{
int i ;
int nType;
int nLen;
CString strMsg;
CString strTmp;
long lUBound;
SAFEARRAY FAR *psa=NULL;
char * pData=NULL;
//create the Associate Class as Request, and set to default
m_pLEADDicomNet->CreateAssociate (TRUE);
m_pLEADDicomNet->DefaultAssociate (m_pLEADDicomNet->GethPDU());
//get current user info types, lengths, and data then display them
strMsg = "Current user type, length, data:";
if (m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()) > 0)
{
for (i = 0; i<m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()); i++)
{
nType = m_pLEADDicomNet->GetUserInfoType (m_pLEADDicomNet->GethPDU(), i);
nLen = m_pLEADDicomNet->GetUserInfoLength(m_pLEADDicomNet->GethPDU(), i);
COleVariant VData = m_pLEADDicomNet->GetUserInfoData (m_pLEADDicomNet->GethPDU(), i);
BSTR bStr = ((LPVARIANT)VData)->bstrVal;
strTmp.Format("Type[%d]\tLength[%d]\tData[%s]", nType, nLen, bStr);
strMsg = strMsg + "\n" + strTmp;
}
}
else
strMsg = strMsg + "\nNone";
AfxMessageBox(strMsg);
//add a user info item item
strMsg = "Add user info item";
COleVariant VDescString;
CString strTest = "Just a test";
VDescString = CString(strTest);
m_pLEADDicomNet->AddUserInfo(m_pLEADDicomNet->GethPDU(), 99, VDescString, strTest.GetLength());
if (m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()) > 0)
{
for (i = 0; i<m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()); i++)
{
nType = m_pLEADDicomNet->GetUserInfoType (m_pLEADDicomNet->GethPDU(), i);
nLen = m_pLEADDicomNet->GetUserInfoLength(m_pLEADDicomNet->GethPDU(), i);
COleVariant VData = m_pLEADDicomNet->GetUserInfoData (m_pLEADDicomNet->GethPDU(), i);
psa = V_ARRAY(&VData);
SafeArrayGetUBound(psa, 1, &lUBound);
SafeArrayAccessData(psa, (void HUGEP**)&pData);
CString strData;
for(int nIndex = 0; nIndex <= lUBound; nIndex++ )
{
strTmp.Format("%c", pData[nIndex]);
strData += strTmp;
}
SafeArrayUnaccessData(psa);
strTmp.Format("Type[%d]\tLength[%d]\tData[%s]", nType, nLen, strData);
strMsg = strMsg + "\n" + strTmp;
}
}
else
strMsg = strMsg + "\nNone";
AfxMessageBox(strMsg);
//for each user info item, change the data
strTest = "a second test";
COleVariant VTest(strTest);
for (i = 0; i<m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()); i++)
{
nType = m_pLEADDicomNet->GetUserInfoType (m_pLEADDicomNet->GethPDU(), i);
m_pLEADDicomNet->SetUserInfo(m_pLEADDicomNet->GethPDU(), i, nType, VTest, strTest.GetLength());
}
strMsg = "Change user data";
if (m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()) > 0)
{
for (i = 0; i<m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()); i++)
{
nType = m_pLEADDicomNet->GetUserInfoType (m_pLEADDicomNet->GethPDU(), i);
nLen = m_pLEADDicomNet->GetUserInfoLength(m_pLEADDicomNet->GethPDU(), i);
COleVariant VData = m_pLEADDicomNet->GetUserInfoData (m_pLEADDicomNet->GethPDU(), i);
psa = V_ARRAY(&VData);
SafeArrayGetUBound(psa, 1, &lUBound);
SafeArrayAccessData(psa, (void HUGEP**)&pData);
CString strData;
for(int nIndex = 0; nIndex <= lUBound; nIndex++ )
{
strTmp.Format("%c", pData[nIndex]);
strData += strTmp;
}
SafeArrayUnaccessData(psa);
strTmp.Format("Type[%d]\tLength[%d]\tData[%s]", nType, nLen, strData);
strMsg = strMsg + "\n" + strTmp;
}
}
else
strMsg = strMsg + "\nNone";
AfxMessageBox(strMsg);
//delete the one we added
m_pLEADDicomNet->DeleteUserInfo(m_pLEADDicomNet->GethPDU(), m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()) - 1);
strMsg = "Delete the added user";
if (m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()) > 0)
{
for (i = 0; i<m_pLEADDicomNet->GetUserInfoCount (m_pLEADDicomNet->GethPDU()); i++)
{
nType = m_pLEADDicomNet->GetUserInfoType (m_pLEADDicomNet->GethPDU(), i);
nLen = m_pLEADDicomNet->GetUserInfoLength(m_pLEADDicomNet->GethPDU(), i);
COleVariant VData = m_pLEADDicomNet->GetUserInfoData (m_pLEADDicomNet->GethPDU(), i);
BSTR bStr = ((LPVARIANT)VData)->bstrVal;
_bstr_t sVal = bStr;
strTmp.Format("Type[%d]\tLength[%d]\tData[%s]", nType, nLen, (char *)sVal);
strMsg = strMsg + "\n" + strTmp;
}
}
else
strMsg = strMsg + "\nNone";
AfxMessageBox(strMsg);
m_pLEADDicomNet->FreeAssociate (m_pLEADDicomNet->GethPDU());
}