shimonek Absent Member.
Absent Member.
2128 views

Adding a user to a distribution list

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);

}
Labels (1)
0 Likes
2 Replies
shimonek Absent Member.
Absent Member.

Re: Adding a user to a distribution list

Update: I think I figured out the eParticipation VARIANT part. Correct me if I am wrong.

VARIANT vti4DLPT;
VariantInit (&vti4DLPT);
vti4DLPT.vt = VT_I4;
vti4DLPT.intVal = eadTo;

That didn't help though. I am still getting an access violation. The following code gives me the same access violation.

pIADDLMembers->Item(pDIADAdminObject, vtbstrDLID, &pDIADDLMember);

But this one works:

pIADDLMembers->CreateIterator(&pDIADDLMembersIterator);

I can retrieve a name using pDIADAdminObject so I know its good. The only thing I can think of is that vtbstrDLID needs to be set to something other than DL1 but what?






>>> On Fri, Jan 22, 2010 at 2:55 PM, in message <4B59BC6E.1CA1.000E.0@bkd.com>, MARK SHIMONEK<MSHIMONEK@bkd.com> wrote:


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);

}
0 Likes
shimonek Absent Member.
Absent Member.

Re: Adding a user to a distribution list

I found the problem. You need to retrieve a distribution list membership using get_Membership instead of get_MemberOf. My working function follows. Hope it helps somebody. BTW, I am using this to copy Exchange users from AD to a GroupWise Foreign PO. This has allowed us to get rid of our less than stellar Novell Exchange gateway. All email is delivered via SMTP. If anyone is in a position to make Exchange and GroupWise work together I highly recommend this approach.

void CDirSyncDlg::EditGW_AddToDL(CString cstrOID, CString cstrDL, CString cstrPO, CString cstrDom)
{
HRESULT hr;
DIADUsers *pDIADUsers = NULL;
DIADAdminObject *pDIADAdminObject = NULL;
IADAdminObject *pIADAdminObject = NULL;
IADUsers *pIADUsers = NULL;
DIADDistributionLists *pDIADDistributionLists = NULL;
IADDistributionLists *pIADDistributionLists = NULL;
DIADDistributionList *pDIADDistributionList = NULL;
IADDistributionList *pIADDistributionList = NULL;
DIADDLMembers *pDIADDLMembers = NULL;
IADDLMembers *pIADDLMembers = NULL;
DIADDLMember *pDIADDLMember = NULL;
BSTR bstrOID = cstrOID.AllocSysString();
BSTR bstrDLID = cstrDL.AllocSysString();


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

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

VARIANT vti4DLPT;
VariantInit (&vti4DLPT);
vti4DLPT.vt = VT_I4;
vti4DLPT.intVal = eadTo;

VARIANT vtbstrDL;
VariantInit (&vtbstrDL);
vtbstrDL.vt = VT_BSTR;
vtbstrDL.bstrVal = cstrDL.AllocSysString();


// Get admin object
hr = pIGWSystem->get_Users(&pDIADUsers);
if(FAILED(hr)) goto CLEANUP;

if(pDIADUsers && SUCCEEDED(pDIADUsers->QueryInterface(
IID_IADUsers, (void**)&pIADUsers))){
pDIADUsers->Release();
}
else goto CLEANUP;

hr = pIADUsers->Item(bstrOID, vtbstrPO, vtbstrDom, (DIADUser **)&pDIADAdminObject);
if(FAILED(hr)) goto CLEANUP;

if(pDIADAdminObject && SUCCEEDED(pDIADAdminObject->QueryInterface(
IID_IADAdminObject, (void**)&pIADAdminObject))){
}
else goto CLEANUP;


// Get distribution list
hr = pIGWSystem->get_DistributionLists( &pDIADDistributionLists );
if(FAILED(hr)) goto CLEANUP;

hr = pDIADDistributionLists->QueryInterface(IID_IADDistributionLists, (void**)&pIADDistributionLists);
if(FAILED(hr)) goto CLEANUP;

hr = pIADDistributionLists->Item(bstrDLID, vtbstrPO, vtbstrDom, &pDIADDistributionList);
if(FAILED(hr)) goto CLEANUP;

if(pDIADDistributionList && SUCCEEDED(pDIADDistributionList->QueryInterface(
IID_IADDistributionList, (void**)&pIADDistributionList))){
pDIADDistributionList->Release();
}
else goto CLEANUP;


// Get distribution list membership
hr = pIADDistributionList->get_Membership(&pDIADDLMembers);
if(FAILED(hr)) goto CLEANUP;

if(pDIADDLMembers && SUCCEEDED(pDIADDLMembers->QueryInterface(
IID_IADDLMembers, (void**)&pIADDLMembers))){
pDIADDLMembers->Release();
}
else goto CLEANUP;


// Add new member to distribution list
hr = pIADDLMembers->Add(pDIADAdminObject, vti4DLPT, vtbstrDL, &pDIADDLMember);
if(FAILED(hr)) goto CLEANUP;


CLEANUP:
VariantClear( &vtbstrPO );
VariantClear( &vtbstrDom );
VariantClear( &vti4DLPT );
VariantClear( &vtbstrDL );

}




>>> On 1/22/2010 at 2:55 PM, in message <4B59BC6E.1CA1.000E.0@bkd.com>, MARK SHIMONEK<MSHIMONEK@bkd.com> wrote:


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);

}
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.