David - here is a c# version of the 2.6.5 eid decoder. We don't have one for 3.0 yet, but it is coming. As always, I have to say that this code is not something to which Microsoft applies any warranties or support guarantees. It is just a starting point
Paul Nystrom - MSFT
static string EIDFromEncodedString(string strEIDEncoded)
{
bool fIsOldStyle = true;
for (int i = 0; i < strEIDEncoded.Length; i++)
{
if (!IsHexDecChar(strEIDEncoded ))
{
fIsOldStyle = false;
break;
}
}
if (fIsOldStyle)
{
return strEIDEncoded;
}
//----------- Decode with YEncode like algorythm -------
// decode using pseudo YENC encoding, everything is shifted up by 0x30 starting it at the '0' letter.
// Things that wrap have an escape '!' followed by a 0x60 to put it back up to '0' letter range
System.Diagnostics.Debug.Assert((strEIDEncoded != null) && (strEIDEncoded.Length > 0));
// //LPCWSTR pszSrc = strEIDU;
// the first WORD is the length of the buffer
// m_cBytes = *pszSrc++ - 0x30;
int cBytes = (int) strEIDEncoded[0] - 0x30;
// add 2 to the size of the buffer since we assume an odd buffer size could lead to a byte being assigned after
// the size of the buffer. This is a side-effect of the way we are encoding the buffer
// AllocateBuffer(m_cBytes+2);
StringBuilder sbEID = new StringBuilder(cBytes+2);
// for each WCHAR in unicode string
// int Len = strEIDU.GetLength();
int Len = strEIDEncoded.Length;
for(int i=1; i < Len; i++)
{
ulong offset = 0x30;
// if it's an escaped char
// if (*pszSrc == '!')
if (strEIDEncoded == '!')
{
// skip escape char
//pszSrc++;
i++;
// offset is now 60
offset = 0x60;
}
// restore current WCHAR
//*pszDest++ = (WCHAR)(((ULONG)*pszSrc + 0x10000) % 0x10000) - offset;
// ulong ulByte = (((ulong)strEIDEncoded + 0x10000) % 0x10000) - offset;
ulong ulByte = (((ulong)strEIDEncoded )&0xffff) - offset;
char ch = (char)(((ulong)strEIDEncoded &0xffff)+offset);
sbEID.AppendFormat("{0:X2}{1:X2}",(ulByte&0x00ff), ulByte >> 8);
// advance to next position
//pszSrc++;
//ATLASSERT((DWORD)((LPBYTE)pszDest - (LPBYTE)m_pEntryId) <= (DWORD)(m_cBytes+2));
}
return sbEID.ToString();
}
|