STDMETHODIMP
CLdapConnection::createEntry(BSTR dn, BSTR attrValuePairs,
VARIANT_BOOL* created=VARIANT_FALSE){
HRESULT hr = S_FALSE;
LDAPMod **mods = NULL;
int rc;
int numberOfModes;
int* arrayValuesDim = NULL;
unsigned int dnLen = _bstr_t(dn).length()+1;
unsigned int attrValuesPairsLen =
_bstr_t(attrValuePairs).length()+1;
char* stAttrValuesPairs = new char[attrValuesPairsLen];
char* stDn = new char[dnLen];
//convert BSTRs to Strs
if(wcstombs(stDn , dn, dnLen ) >0 && dnLen >1)
if(wcstombs(stAttrValuesPairs , attrValuePairs,
attrValuesPairsLen ) >=0 &&
attrValuesPairsLen >= 1{//start
//parse the attributes and values string
char delimiter =';';
numberOfModes =
GetNumberOfAttributes(stAttrValuesPairs ,delimiter);
//array to hold value array dimension
arrayValuesDim= new int[numberOfModes];
//allocate mods
mods = allocateMods(mods, numberOfModes);
if(mods != NULL){
//initialize mods & allocates mod_values
initializeMods(mods, stAttrValuesPairs,
arrayValuesDim);
//Perform the add operation
rc = ldap_add_ext_s( ld, stDn, mods, NULL, NULL );
//deallocate mods
deallocateMods(mods,numberOfModes,arrayValuesDim);
}
//get the error if any
if(rc != LDAP_SUCCESS){
stLDAPError = ldap_err2string(rc);
}else{
//set OK
*created = VARIANT_TRUE;
hr = S_OK;
}
if(arrayValuesDim != NULL)
delete[]arrayValuesDim;
}//end
delete[]stAttrValuesPairs;
delete[]stDn;
return hr;
}