I hope someone can tell me what I am doing wrong. I am trying to add my user to the DL1 distribution list using the following code but the last statemenet (Add) gives me a C0000005 Access violation. Everything works perfectly up to that point. I don't know if this is my problem but the function requests parameters of type VARIANT eParticipationType and VARIANT DistributinList. I could not find anything that describes how these would be created. I tried using VT_BSTR with eadTo, To and VT_INT but it didn't make a difference. I tried a couple different ways of retrieving the IADDLMembers object but that didn't seem to matter either.


void CDirSyncDlg::EditGW_Test()
{
HRESULT hr;

DIADUsers *pDIADUsers = NULL;
IADUsers *pIADUsers = NULL;
DIADUser *pDIADUser = NULL;
IADUser *pIADUser = NULL;


pIGWSystem->get_Users(&pDIADUsers);

pDIADUsers->QueryInterface(IID_IADUsers, (void**)&pIADUsers);


CString cstrOID = "mshimonek";
BSTR bstrOID = cstrOID.AllocSysString();

CString cstrPO = "Archive_PO";
VARIANT vtbstrPO;
VariantInit (&vtbstrPO);
vtbstrPO.vt = VT_BSTR;
vtbstrPO.bstrVal = cstrPO.AllocSysString();

CString cstrDom = "Archive";
VARIANT vtbstrDom;
VariantInit (&vtbstrDom);
vtbstrDom.vt = VT_BSTR;
vtbstrDom.bstrVal = cstrDom.AllocSysString();

DIADAdminObject *pDIADAdminObject = NULL;

hr = pIADUsers->Item(bstrOID, vtbstrPO, vtbstrDom, (DIADUser **)&pDIADAdminObject);
hr = pIADUsers->Item(bstrOID, vtbstrPO, vtbstrDom, &pDIADUser);

pDIADUser->QueryInterface(IID_IADUser, (void**)&pIADUser);

DIADDistributionLists *pDIADDistributionLists = NULL;
IADDistributionLists *pIADDistributionLists = NULL;

pIGWSystem->get_DistributionLists( &pDIADDistributionLists );

pDIADDistributionLists->QueryInterface(IID_IADDistributionLists, (void**)&pIADDistributionLists);


CString cstrDLID = "DL1";
BSTR bstrDLID = cstrDLID.AllocSysString();

DIADDistributionList *pDIADDistributionList = NULL;
IADDistributionList *pIADDistributionList = NULL;

pIADDistributionLists->Item(bstrDLID, vtbstrPO, vtbstrDom, &pDIADDistributionList);

pDIADDistributionList->QueryInterface(IID_IADDistributionList, (void**)&pIADDistributionList);


DIADDLMembers *pDIADDLMembers = NULL;
IADDLMembers *pIADDLMembers = NULL;

//pIADDistributionList->get_MemberOf(&pDIADDLMembers);
pIADUser->get_MemberOf(&pDIADDLMembers);

pDIADDLMembers->QueryInterface(IID_IADDLMembers, (void**)&pIADDLMembers);


DIADDLMember *pDIADDLMember = NULL;

CString cstrDLPT = "To";
VARIANT vtbstrDLPT;
VariantInit (&vtbstrDLPT);
vtbstrDLPT.vt = VT_BSTR;
vtbstrDLPT.bstrVal = cstrDLPT.AllocSysString();

VARIANT vtintDLPT;
VariantInit (&vtintDLPT);
vtintDLPT.vt = VT_INT;
vtintDLPT.intVal = 0;

VARIANT vtbstrDLID;
VariantInit (&vtbstrDLID);
vtbstrDLID.vt = VT_BSTR;
vtbstrDLID.bstrVal = cstrDLID.AllocSysString();


pIADDLMembers->Add(pDIADAdminObject, vtintDLPT, vtbstrDLID, &pDIADDLMember);

}