IAddressBook | developer.brewmp.com IAddressBook | developer.brewmp.com

Developer

IAddressBook

Forums:

Hi all,

I want to add a contact to my contact list. I am using the below code to add a name. The code is working with the emulator. I can able to see the name in phbk file(some file created inside the address folder). Now the same code is not able to create the record. It is giving the error 779 i.e AEE_ADDR_INVALID_FIELD_VALUE. Please help me in solving this issue.

static boolean TestIAddrBook(MsLive* pMe,boolean bFirstTime, boolean bRefresh)
{
char *szName = "Name1";
char *szPhoneNo = "123456789";

AEEAddrField field[1] = { {AEE_ADDRFIELD_FIRSTNAME,AEEDB_FT_STRING,szName,STRLEN(szName)}

};

RELEASEIF(pMe->pIAddrBook);
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_ADDRBOOK,
(void **)&pMe->pIAddrBook)!= SUCCESS)
{
pMe->pIAddrBook = NULL;
DBGPRINTF("IAddrBook CreateInstance Failed");
return FALSE;
}
DBGPRINTF("INside TestIAddrBook");
if(IADDRBOOK_CreateRec(pMe->pIAddrBook,AEE_ADDR_CAT_USER + 1,field,1)!= NULL)
{
//Addressbook record created
DBGPRINTF("Created a record Successfully");

}
else
{
DBGPRINTF("Last Error :: %d", IADDRBOOK_GetLastError(pMe->pIAddrBook));
DBGPRINTF("Cannot able to create a record");

}
//IADDRBOOK_Release(pMe->pIAddrBook);
RELEASEIF(pMe->pIAddrBook);
return TRUE;

Regards,
Syed

I think that your issue may be because an AEEDB_FT_STRING field is supposed to be an AECHAR array and you are using a char array. Additionally, it is supposed to be NULL terminated, so you will need to include that NULL character in wDataLen, so this is probably what you want:
AECHAR *szName = (AECHAR *)L"Name1";
AEEAddrField field[1] = {{AEE_ADDRFIELD_FIRSTNAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1) * sizeof(AECHAR)}};

I think that your issue may be because an AEEDB_FT_STRING field is supposed to be an AECHAR array and you are using a char array. Additionally, it is supposed to be NULL terminated, so you will need to include that NULL character in wDataLen, so this is probably what you want:
AECHAR *szName = (AECHAR *)L"Name1";
AEEAddrField field[1] = {{AEE_ADDRFIELD_FIRSTNAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1) * sizeof(AECHAR)}};

Hi Greg,
Thanks for your reply. I tried that but the problem still persists. The last error is 779 itself. Any other modifications which i can do.
Regards,
Syed

Hi Greg,
Thanks for your reply. I tried that but the problem still persists. The last error is 779 itself. Any other modifications which i can do.
Regards,
Syed

Hi Friends,
I tried to change different options of AEEAddrCat
IADDRBOOK_CreateRec(pMe->pIAddrBook,AEE_ADDR_CAT_USER + 1,field,1); but nothing seems to be working. I don't know where i am doing mistake.
Please help to solve this issue. While to code is creating a address folder and storing the name in a phbk file. Where as it is not working on mobile.
I am using Motorola V3C. If there is any sample which can create a contact in the address book please share it.
Thanks,
Syed

Hi Friends,
I tried to change different options of AEEAddrCat
IADDRBOOK_CreateRec(pMe->pIAddrBook,AEE_ADDR_CAT_USER + 1,field,1); but nothing seems to be working. I don't know where i am doing mistake.
Please help to solve this issue. While to code is creating a address folder and storing the name in a phbk file. Where as it is not working on mobile.
I am using Motorola V3C. If there is any sample which can create a contact in the address book please share it.
Thanks,
Syed

Hi syedba,
Try to trace the return value on the handset using BREW Logger.
Good Luck...!

Hi syedba,
Try to trace the return value on the handset using BREW Logger.
Good Luck...!

Hi Abhimanyu,
Thanks for your reply.
Actually i specified that error code is 779. So the return value is null as per the code. Any other idea where i am doing wrong :confused:
Regards,
Syed

Hi Abhimanyu,
Thanks for your reply.
Actually i specified that error code is 779. So the return value is null as per the code. Any other idea where i am doing wrong :confused:
Regards,
Syed

Try this out
AEEAddrField field[2];
AECHAR *szName = L"Name1";
AECHAR *szPhoneNo = L"123456789";
field[0].fID = AEE_ADDRFIELD_NAME;
field[0].fType = AEEDB_FT_STRING;
field[0].pBuffer = (void*)szName;
field[0].wDataLen = sizeof(AECHAR) * WSTRLEN(szName);
field[1].fID = AEE_ADDRFIELD_PHONE_WORK;
field[1].fType = AEEDB_FT_PHONE;
field[1].pBuffer= (void*)szPhoneNo;
field[1].wDataLen = sizeof(AECHAR) * WSTRLEN(szPhoneNo);
if(IADDRBOOK_CreateRe(pMe>m_pAddrBook,AEE_ADDR_CAT_PERSONAL,field,2)!= NULL)
{
//Addressbook record created
DBGPRINTF("Created a record Successfully");
}
else
{
DBGPRINTF("Last Error :: %d", IADDRBOOK_GetLastError(pMe->m_pAddrBook));
DBGPRINTF("Cannot able to create a record");
}
I guess the problem with your code is that you have not filled in values for field[0].

Try this out
AEEAddrField field[2];
AECHAR *szName = L"Name1";
AECHAR *szPhoneNo = L"123456789";
field[0].fID = AEE_ADDRFIELD_NAME;
field[0].fType = AEEDB_FT_STRING;
field[0].pBuffer = (void*)szName;
field[0].wDataLen = sizeof(AECHAR) * WSTRLEN(szName);
field[1].fID = AEE_ADDRFIELD_PHONE_WORK;
field[1].fType = AEEDB_FT_PHONE;
field[1].pBuffer= (void*)szPhoneNo;
field[1].wDataLen = sizeof(AECHAR) * WSTRLEN(szPhoneNo);
if(IADDRBOOK_CreateRe(pMe>m_pAddrBook,AEE_ADDR_CAT_PERSONAL,field,2)!= NULL)
{
//Addressbook record created
DBGPRINTF("Created a record Successfully");
}
else
{
DBGPRINTF("Last Error :: %d", IADDRBOOK_GetLastError(pMe->m_pAddrBook));
DBGPRINTF("Cannot able to create a record");
}
I guess the problem with your code is that you have not filled in values for field[0].

Thanks a lot ,lot and lot Shashi.
Finally it got solved with the idea you gave.
Actual problem is i am trying to create the contact with only name and phone number was not there. So it was giving error 779 i.e AEE_ADDR_INVALID_FIELD_VALUE.
I initialized the phone number fields then it was creating the contact.
Here is the code which i am using now:
AECHAR *szName = L"Syed2";
AECHAR *szPhoneNo = L"123456789";
IAddrRec* pIAddrRec = NULL;
AEEAddrField field[2] = {
{AEE_ADDRFIELD_NAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1)* sizeof(AECHAR)},
{AEE_ADDRFIELD_PHONE_CELL,AEEDB_FT_PHONE,szPhoneNo, (WSTRLEN(szPhoneNo) + 1)* sizeof(AECHAR)}
};
RELEASEIF(pMe->pIAddrBook);
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_ADDRBOOK,
(void **)&pMe->pIAddrBook)!= SUCCESS)
{
pMe->pIAddrBook = NULL;
DBGPRINTF("IAddrBook CreateInstance Failed");
return FALSE;
}
DBGPRINTF("Name :: %s",szName);
DBGPRINTF("Phone :: %s",szPhoneNo);
if(IADDRBOOK_CreateRec(pMe->pIAddrBook,AEE_ADDR_CAT_USER+1,field,2)!= NULL)
{
//Addressbook record created
DBGPRINTF("Created a record Successfully");
}
else
{
DBGPRINTF("Last Error :: %d", IADDRBOOK_GetLastError(pMe->pIAddrBook));
DBGPRINTF("Cannot able to create a record");
}
//IADDRBOOK_Release(pMe->pIAddrBook);
RELEASEIF(pMe->pIAddrBook);
return TRUE;
And now the problem is it is displaying only only first two characters ie. S and 1. How to fix this problem?
Regards,
Syed

Thanks a lot ,lot and lot Shashi.
Finally it got solved with the idea you gave.
Actual problem is i am trying to create the contact with only name and phone number was not there. So it was giving error 779 i.e AEE_ADDR_INVALID_FIELD_VALUE.
I initialized the phone number fields then it was creating the contact.
Here is the code which i am using now:
AECHAR *szName = L"Syed2";
AECHAR *szPhoneNo = L"123456789";
IAddrRec* pIAddrRec = NULL;
AEEAddrField field[2] = {
{AEE_ADDRFIELD_NAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1)* sizeof(AECHAR)},
{AEE_ADDRFIELD_PHONE_CELL,AEEDB_FT_PHONE,szPhoneNo, (WSTRLEN(szPhoneNo) + 1)* sizeof(AECHAR)}
};
RELEASEIF(pMe->pIAddrBook);
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_ADDRBOOK,
(void **)&pMe->pIAddrBook)!= SUCCESS)
{
pMe->pIAddrBook = NULL;
DBGPRINTF("IAddrBook CreateInstance Failed");
return FALSE;
}
DBGPRINTF("Name :: %s",szName);
DBGPRINTF("Phone :: %s",szPhoneNo);
if(IADDRBOOK_CreateRec(pMe->pIAddrBook,AEE_ADDR_CAT_USER+1,field,2)!= NULL)
{
//Addressbook record created
DBGPRINTF("Created a record Successfully");
}
else
{
DBGPRINTF("Last Error :: %d", IADDRBOOK_GetLastError(pMe->pIAddrBook));
DBGPRINTF("Cannot able to create a record");
}
//IADDRBOOK_Release(pMe->pIAddrBook);
RELEASEIF(pMe->pIAddrBook);
return TRUE;
And now the problem is it is displaying only only first two characters ie. S and 1. How to fix this problem?
Regards,
Syed

Hi Syed,
AEEAddrField field[2] = {
{AEE_ADDRFIELD_NAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1)* sizeof(AECHAR)},
{AEE_ADDRFIELD_PHONE_CELL,AEEDB_FT_PHONE,szPhoneNo, (WSTRLEN(szPhoneNo) + 1)* sizeof(AECHAR)}
};
I am unable to compile the above code snippet with arm compiler.
"addrbook.c", line 11: Serious error: C2432E: non-constant initialiser
"addrbook.c", line 11: Serious error: C2965E: illegal in static integral type in
itialiser:
"addrbook.c", line 12: Serious error: C2432E: non-constant initialiser
"addrbook.c", line 12: Serious error: C2965E: illegal in static integral type in
itialiser:
Try replacing this part of the code with the code I have given. It should work. Else you've got to debug and find out.
Regards,
Shashi Kant

Hi Syed,
AEEAddrField field[2] = {
{AEE_ADDRFIELD_NAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1)* sizeof(AECHAR)},
{AEE_ADDRFIELD_PHONE_CELL,AEEDB_FT_PHONE,szPhoneNo, (WSTRLEN(szPhoneNo) + 1)* sizeof(AECHAR)}
};
I am unable to compile the above code snippet with arm compiler.
"addrbook.c", line 11: Serious error: C2432E: non-constant initialiser
"addrbook.c", line 11: Serious error: C2965E: illegal in static integral type in
itialiser:
"addrbook.c", line 12: Serious error: C2432E: non-constant initialiser
"addrbook.c", line 12: Serious error: C2965E: illegal in static integral type in
itialiser:
Try replacing this part of the code with the code I have given. It should work. Else you've got to debug and find out.
Regards,
Shashi Kant

syedba wrote:And now the problem is it is displaying only only first two characters ie. S and 1. How to fix this problem?Is this when you look at the actual contact in the address book or from your DBGPRINTF call? If it is your DBGPRINTF call, then that would be correct since you are using an AECHAR/wide string (what the "L" in front of the string does) as a char string. Since a wide string is basically just a char string null padded to 2 bytes per character, it does appear to be just the first letter followed by the null termination character when you cast it as a char string.

syedba wrote:And now the problem is it is displaying only only first two characters ie. S and 1. How to fix this problem?Is this when you look at the actual contact in the address book or from your DBGPRINTF call? If it is your DBGPRINTF call, then that would be correct since you are using an AECHAR/wide string (what the "L" in front of the string does) as a char string. Since a wide string is basically just a char string null padded to 2 bytes per character, it does appear to be just the first letter followed by the null termination character when you cast it as a char string.

Hi Shashi,
Problem remains the same even after change. I don't think that is the problem. Some problem related to AECHAR (I guess).
Regards,
Syed

Hi Shashi,
Problem remains the same even after change. I don't think that is the problem. Some problem related to AECHAR (I guess).
Regards,
Syed

Hi Greg,
It is displaying in DBGPRINTF function as
Name :: S
Phone :: 1
And even in the contact list of Motorola V3C it is displaying the same.
If i use char instead of AECHAR, then it is displaying Squares with only last letter in mobile whereas in DBGPRINTF is is displaying properly.
ie
Name :: Syed2
Phone :: 123456789 in DBGPRINTF
In Contact list it is displaying
[][]2
00009
Please consider [] as a square. :(
I think for every 2 character it is displaying one [] and 0 respectively.
There is some problem in displaying the string. Please help with your valuable thoughts. :)
Regards,
syed

Hi Greg,
It is displaying in DBGPRINTF function as
Name :: S
Phone :: 1
And even in the contact list of Motorola V3C it is displaying the same.
If i use char instead of AECHAR, then it is displaying Squares with only last letter in mobile whereas in DBGPRINTF is is displaying properly.
ie
Name :: Syed2
Phone :: 123456789 in DBGPRINTF
In Contact list it is displaying
[][]2
00009
Please consider [] as a square. :(
I think for every 2 character it is displaying one [] and 0 respectively.
There is some problem in displaying the string. Please help with your valuable thoughts. :)
Regards,
syed

Hi Syed,
What is RELEASEIF () doing in your code? Is it same as FREEIF ().? I ran your code using FREEIF () instead of RELEASEIF () (As I dont know what it means in your code) and got the correct result on device.
Also in the DBGPRINTF statements you should use %S format specifiers for wide chars instead of %s.
Regards,
Shashi Kant

Hi Syed,
What is RELEASEIF () doing in your code? Is it same as FREEIF ().? I ran your code using FREEIF () instead of RELEASEIF () (As I dont know what it means in your code) and got the correct result on device.
Also in the DBGPRINTF statements you should use %S format specifiers for wide chars instead of %s.
Regards,
Shashi Kant

Hi all,
The problem got solved. I used a STRTOWSTR() and it got solved. Thanks to all for ur valuable inputs ;)
Regards,
Syed

Hi all,
The problem got solved. I used a STRTOWSTR() and it got solved. Thanks to all for ur valuable inputs ;)
Regards,
Syed

Just to reiterate, what you were seeing was the correct behavior as you were trying to use an AECHAR string as a char string. I guess I am just wondering why you seem to be so concerned about what DBGPRINTF is printing if it is coming out correctly in the actual address book. It's just that it seems like an extra step just so you can do a DBGPRINTF, but using STRTOWSTR to convert the char string to an AECHAR string is fine, I guess.
Shashi Kant wrote:Also in the DBGPRINTF statements you should use %S format specifiers for wide chars instead of %s.I'm not sure that this would work correctly on a handset since I think that %S may be a Microsoft specific printf specifier.

Just to reiterate, what you were seeing was the correct behavior as you were trying to use an AECHAR string as a char string. I guess I am just wondering why you seem to be so concerned about what DBGPRINTF is printing if it is coming out correctly in the actual address book. It's just that it seems like an extra step just so you can do a DBGPRINTF, but using STRTOWSTR to convert the char string to an AECHAR string is fine, I guess.
Shashi Kant wrote:Also in the DBGPRINTF statements you should use %S format specifiers for wide chars instead of %s.I'm not sure that this would work correctly on a handset since I think that %S may be a Microsoft specific printf specifier.

Greg, check the docs for SPRINTF (since DBGPRINTF uses the same format characters) and you'll see that %S allows you to insert a wide string.
-Erik

Greg, check the docs for SPRINTF (since DBGPRINTF uses the same format characters) and you'll see that %S allows you to insert a wide string.
-Erik

By using DBGPRINTF i tried printing both char and AECHAR. char supports %s and AECHAR supports %S.
When i tried to print char with %S it is giving some unknown value. I am not sure whether it is real junk or converted to any other format.
Any how Thanks a lot. That problem got solved. :)
- Syed ;)

By using DBGPRINTF i tried printing both char and AECHAR. char supports %s and AECHAR supports %S.
When i tried to print char with %S it is giving some unknown value. I am not sure whether it is real junk or converted to any other format.
Any how Thanks a lot. That problem got solved. :)
- Syed ;)

AECHAR *szName = L"Syed2";
AECHAR *szPhoneNo = L"123456789";
IAddrRec* pIAddrRec = NULL;
AEEAddrField field[2] = {
{AEE_ADDRFIELD_NAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1)* sizeof(AECHAR)},
{AEE_ADDRFIELD_PHONE_CELL,AEEDB_FT_PHONE,szPhoneNo , (WSTRLEN(szPhoneNo) + 1)* sizeof(AECHAR)}
};
RELEASEIF(pMe->pIAddrBook);
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_ADDRBOOK,
(void **)&pMe->pIAddrBook)!= SUCCESS)
{
pMe->pIAddrBook = NULL;
DBGPRINTF("IAddrBook CreateInstance Failed");
return FALSE;
}
DBGPRINTF("Name :: %s",szName);
DBGPRINTF("Phone :: %s",szPhoneNo);
if(IADDRBOOK_CreateRec(pMe->pIAddrBook,AEE_ADDR_CAT_USER+1,field,2)!= NULL)
{
//Addressbook record created
DBGPRINTF("Created a record Successfully");
}
else
{
DBGPRINTF("Last Error :: %d", IADDRBOOK_GetLastError(pMe->pIAddrBook));
DBGPRINTF("Cannot able to create a record");
}
//IADDRBOOK_Release(pMe->pIAddrBook);
RELEASEIF(pMe->pIAddrBook);
return TRUE;
does the above code work on the 3.1.5 simulator?
because when i tried that code the CreateInstance is failing.
what could have been the possible reason?
thanks for helping a biginer like me...
tirthadeep

AECHAR *szName = L"Syed2";
AECHAR *szPhoneNo = L"123456789";
IAddrRec* pIAddrRec = NULL;
AEEAddrField field[2] = {
{AEE_ADDRFIELD_NAME, AEEDB_FT_STRING, szName, (WSTRLEN(szName) + 1)* sizeof(AECHAR)},
{AEE_ADDRFIELD_PHONE_CELL,AEEDB_FT_PHONE,szPhoneNo , (WSTRLEN(szPhoneNo) + 1)* sizeof(AECHAR)}
};
RELEASEIF(pMe->pIAddrBook);
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_ADDRBOOK,
(void **)&pMe->pIAddrBook)!= SUCCESS)
{
pMe->pIAddrBook = NULL;
DBGPRINTF("IAddrBook CreateInstance Failed");
return FALSE;
}
DBGPRINTF("Name :: %s",szName);
DBGPRINTF("Phone :: %s",szPhoneNo);
if(IADDRBOOK_CreateRec(pMe->pIAddrBook,AEE_ADDR_CAT_USER+1,field,2)!= NULL)
{
//Addressbook record created
DBGPRINTF("Created a record Successfully");
}
else
{
DBGPRINTF("Last Error :: %d", IADDRBOOK_GetLastError(pMe->pIAddrBook));
DBGPRINTF("Cannot able to create a record");
}
//IADDRBOOK_Release(pMe->pIAddrBook);
RELEASEIF(pMe->pIAddrBook);
return TRUE;
does the above code work on the 3.1.5 simulator?
because when i tried that code the CreateInstance is failing.
what could have been the possible reason?
thanks for helping a biginer like me...
tirthadeep

Hi, tirthadeep
tirthadeep wrote:
because when i tried that code the CreateInstance is failing.
what could have been the possible reason?
check the address book privileges in the mif of your application.

Hi, tirthadeep
tirthadeep wrote:
because when i tried that code the CreateInstance is failing.
what could have been the possible reason?
check the address book privileges in the mif of your application.