problem with updating addrbook field in device | developer.brewmp.com problem with updating addrbook field in device | developer.brewmp.com

Developer

problem with updating addrbook field in device

Forums:

Hi,

I am newbie to brew. I create the record in device motorola k1m it successfully created but problem with updating the field and i want to update a record field in the device but it give me the error "781" means "invalid record" i dont know why. My code for update field is

void Update_Field(BREW1* pMe)
{
int i;
char* Buff = (char*)MALLOC(100);
pMe->pName = (AECHAR*)MALLOC(24);
pMe->pPhone = (AECHAR*)MALLOC(41);

STRTOWSTR("Ibrahim",pMe->pName,24*sizeof(AECHAR));
pMe->Add_ERec = IADDRBOOK_EnumRecInit(pMe->pAddrBook,AEE_ADDR_CAT_NONE,AEE_ADDRFIELD_NAME,pMe->pName,(WSTRLEN(pMe->pName)+1)*sizeof(AECHAR));
if (pMe->Add_ERec == AEE_SUCCESS)
{
pMe->pAddrRec = IADDRBOOK_EnumNextRec(pMe->pAddrBook);
if (pMe->pAddrRec)
{
pMe->Add_Count = IADDRREC_GetFieldCount(pMe->pAddrRec);
for (i = 0; i < pMe->Add_Count; i++)
{
pMe->pField = IADDRREC_GetField(pMe->pAddrRec,i);
SPRINTF(Buff,"%d",i);
DBGPRINTF(Buff);
if(pMe->pField->fID == AEE_ADDRFIELD_PHONE_CELL)
break;
}
if(pMe->pField)
{
pMe->nField.fID = pMe->pField->fID;
pMe->nField.fType = pMe->pField->fType;
WSTRTOSTR(pMe->pField->pBuffer,Buff,WSTRLEN(pMe->pField->pBuffer)+1);
DBGPRINTF(Buff);
STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
pMe->nField.pBuffer = pMe->pPhone;
pMe->nField.wDataLen = (WSTRLEN(pMe->pPhone)+1)*sizeof(AECHAR);
SPRINTF(Buff,"%d",i);
DBGPRINTF(Buff);

pMe->err = IADDRREC_UpdateField(pMe->pAddrRec,i,&pMe->nField);
if (pMe->err == AEE_SUCCESS)
DBGPRINTF("Update Success");
else
{
pMe->err = IADDRREC_GetLastError(pMe->pAddrRec);
DBGPRINTF("Update Failed");
SPRINTF(Buff,"%d",pMe->err);
DBGPRINTF(Buff);
}
}
else
DBGPRINTF("Field Failed");
}
else
DBGPRINTF("ADDRREC Failed");
}

if (pMe->pAddrRec)
{
IADDRREC_Release(pMe->pAddrRec);
pMe->pAddrRec = NULL;
}

FREEIF(Buff);
FREEIF(pMe->pPhone);
FREEIF(pMe->pName);

Plz guide me what is the problem in my code

Thanks

Motorola OEMAddrbook will validate all the field. The error seems that your updated data can not pass the validation in OEM layer.
I suspected your below code has some problem:
Why use 41 in STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
=====================================================
pMe->nField.fID = pMe->pField->fID;
pMe->nField.fType = pMe->pField->fType;
WSTRTOSTR(pMe->pField->pBuffer,Buff,WSTRLEN(pMe->pField->pBuffer)+1);
DBGPRINTF(Buff);
STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
pMe->nField.pBuffer = pMe->pPhone;
pMe->nField.wDataLen = (WSTRLEN(pMe->pPhone)+1)*sizeof(AECHAR);
=====================================================

Motorola OEMAddrbook will validate all the field. The error seems that your updated data can not pass the validation in OEM layer.
I suspected your below code has some problem:
Why use 41 in STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
=====================================================
pMe->nField.fID = pMe->pField->fID;
pMe->nField.fType = pMe->pField->fType;
WSTRTOSTR(pMe->pField->pBuffer,Buff,WSTRLEN(pMe->pField->pBuffer)+1);
DBGPRINTF(Buff);
STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
pMe->nField.pBuffer = pMe->pPhone;
pMe->nField.wDataLen = (WSTRLEN(pMe->pPhone)+1)*sizeof(AECHAR);
=====================================================

Hi,
what the problem in the following code plz also mention it
pMe->nField.fID = pMe->pField->fID;
pMe->nField.fType = pMe->pField->fType;
WSTRTOSTR(pMe->pField->pBuffer,Buff,WSTRLEN(pMe->pField->pBuffer)+1);
DBGPRINTF(Buff);
STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
pMe->nField.pBuffer = pMe->pPhone;
pMe->nField.wDataLen = (WSTRLEN(pMe->pPhone)+1)*sizeof(AECHAR);
when i call the following line it given me the error of "781"
pMe->err = IADDRREC_UpdateField(pMe->pAddrRec,i,&pMe->nField);
so if anybody know where i am wrong so plz mention it
Thanks

Hi,
what the problem in the following code plz also mention it
pMe->nField.fID = pMe->pField->fID;
pMe->nField.fType = pMe->pField->fType;
WSTRTOSTR(pMe->pField->pBuffer,Buff,WSTRLEN(pMe->pField->pBuffer)+1);
DBGPRINTF(Buff);
STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
pMe->nField.pBuffer = pMe->pPhone;
pMe->nField.wDataLen = (WSTRLEN(pMe->pPhone)+1)*sizeof(AECHAR);
when i call the following line it given me the error of "781"
pMe->err = IADDRREC_UpdateField(pMe->pAddrRec,i,&pMe->nField);
so if anybody know where i am wrong so plz mention it
Thanks

abbay wrote:Hi,
what the problem in the following code plz also mention it
pMe->nField.fID = pMe->pField->fID;
pMe->nField.fType = pMe->pField->fType;
WSTRTOSTR(pMe->pField->pBuffer,Buff,WSTRLEN(pMe->pField->pBuffer)+1);
DBGPRINTF(Buff);
STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
pMe->nField.pBuffer = pMe->pPhone;
pMe->nField.wDataLen = (WSTRLEN(pMe->pPhone)+1)*sizeof(AECHAR);
when i call the following line it given me the error of "781"
pMe->err = IADDRREC_UpdateField(pMe->pAddrRec,i,&pMe->nField);
so if anybody know where i am wrong so plz mention it
Thanks
WSTRTOSTR and STRTOWSTR both take a parameter nSize which specifies the size of the buffer in bytes, not AECHARs.
Your WSTRTOSTR line is wrong because argument 3 is too small - you should be passing 2 * (WSTRLEN(pMe->pField->pBuffer) + 1). It's also wrong because that isn't the size of Buff in any case - you should calculate the size of Buff, not just allocate 100 bytes.
Your STRTOWSTR line is wrong because pMe->pPhone is 41 bytes long, but you are attempting to copy up to 82 bytes into it.
This line is wrong:
if(pMe->pField)
You should write:
if(i < pMe->Add_Count)
As it is possible that you never find the AEE_ADDRFIELD_PHONE_CELL record.
There could be a bunch of other problems, but that feels like a good start...
The Motorola V3 doesn't allow AEE_ADDR_CAT_NONE. Maybe the K1M doesn't either.

abbay wrote:Hi,
what the problem in the following code plz also mention it
pMe->nField.fID = pMe->pField->fID;
pMe->nField.fType = pMe->pField->fType;
WSTRTOSTR(pMe->pField->pBuffer,Buff,WSTRLEN(pMe->pField->pBuffer)+1);
DBGPRINTF(Buff);
STRTOWSTR("009234523216",pMe->pPhone,41*sizeof(AECHAR));
pMe->nField.pBuffer = pMe->pPhone;
pMe->nField.wDataLen = (WSTRLEN(pMe->pPhone)+1)*sizeof(AECHAR);
when i call the following line it given me the error of "781"
pMe->err = IADDRREC_UpdateField(pMe->pAddrRec,i,&pMe->nField);
so if anybody know where i am wrong so plz mention it
Thanks
WSTRTOSTR and STRTOWSTR both take a parameter nSize which specifies the size of the buffer in bytes, not AECHARs.
Your WSTRTOSTR line is wrong because argument 3 is too small - you should be passing 2 * (WSTRLEN(pMe->pField->pBuffer) + 1). It's also wrong because that isn't the size of Buff in any case - you should calculate the size of Buff, not just allocate 100 bytes.
Your STRTOWSTR line is wrong because pMe->pPhone is 41 bytes long, but you are attempting to copy up to 82 bytes into it.
This line is wrong:
if(pMe->pField)
You should write:
if(i < pMe->Add_Count)
As it is possible that you never find the AEE_ADDRFIELD_PHONE_CELL record.
There could be a bunch of other problems, but that feels like a good start...
The Motorola V3 doesn't allow AEE_ADDR_CAT_NONE. Maybe the K1M doesn't either.

The K1M does not use that define. Try
#define AEE_ADDR_CAT_GENERAL AEE_ADDR_CAT_USER + 1

The K1M does not use that define. Try
#define AEE_ADDR_CAT_GENERAL AEE_ADDR_CAT_USER + 1

hi
thanks for your reply,but the problem is still occuring if anybody have a code for addressbook update field and remove field which works fine in device then plz post it. I am very thankful to her/him.
plz help me
thanks

hi
thanks for your reply,but the problem is still occuring if anybody have a code for addressbook update field and remove field which works fine in device then plz post it. I am very thankful to her/him.
plz help me
thanks