Following my post last week regarding the bug in the Windows Mobile 5.0 Managed Telephony API, I received questions from several people asking what the affect of the suggested work around will be when the API gets fixed.
In other words, if you explicitly add a null (\0) character to the end of the phone number to work around the current bug, will the code fail when the API gets fixed which then will result in two null characters at the end of the string (the null added for the workaround plus the null added by the Managed API).
The good news is that there's nothing to worry about. Remember that the string is being passed to a C API (PhoneMakeCall) which means that it will read the value in the passed number up to the first null (\0) character. It doesn't matter how many null characters follow it.
If you've not worked with C/C++, this point may not be quite clear. As an example, consider the following C code to make a phone call:
// Declare phone number buffer and PHONEMAKECALLINFO struct
TCHAR tszPhoneNumber[64];
PHONEMAKECALLINFO pmcInfo = {0};
// Initialize PHONEMAKECALLINFO structure
pmcInfo.cbSize = sizeof(pmcInfo);
pmcInfo.dwFlags = PMCF_DEFAULT;
// Fill the phone number buffer with null characters
memset(tszPhoneNumber, _T('\0'), sizeof(tszPhoneNumber));
// Copy the phone number into the phone number buffer
_tcscpy(tszPhoneNumber, _T("6035551212"));
// Associate the phone number buffer with the PHONEMAKECALLINFO struct
pmcInfo.pszDestAddress = tszPhoneNumber;
// Make the call
PhoneMakeCall(&pmcInfo);
In this example, the phone number buffer is initially filled with 64 null characters. The 10 character phone number is then copied to the phone number buffer which is then associated with the PHONEMAKECALLINFO structure.
Following the copying of the phone number, the buffer contains 54 trailing null characters. The code works with no problems because the rule for C strings (character arrays technically) is that the string value ends at the first occurrence of a null character (\0). This is similar to what the case will be when the Managed Telephony API gets fixed.
It doesn't matter how many null characters are at the end of the string as long there's at least one. J
Posted
Jan 31 2006, 02:41 PM
by
jim-wilson