Where is IIDFromString on Windows CE?


IIDFromString is a function exported by ole32.lib in order to get a GUID from a WCHAR* string.  I get asked why doesn't Windows CE ole32.lib support this functionality, since it's a reasonably common thing to do.


The answer is CE does support this function, but unfortunately it's only available in the DCOM builds of our COM.  DCOM adds like 500KB ROM to your image, which is why most CE platform do not include it (including PPC + SmartPhone -- or I should say "Windows Mobile" or the marketing people will yell at me).


I've had to deal with this enough that I've written a small function to do about the equivalent of IIDFromString.  It will be in CE 6.0 in everyone's favorite utility file (svsutil.hxx).  I'm posting it here since it's handy and I've been asked a bunch of questions on this recently.


#define SVSUTIL_GUID_FORMAT_W   L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"


inline BOOL svsutil_ReadGuidW(const WCHAR *szGuid, GUID *pGuid) {
 DWORD data1, data2, data3;
 DWORD data4[8];
 DWORD i;


 if (11 != swscanf(szGuid,L"{" SVSUTIL_GUID_FORMAT_W L"}" ,
  &data1, &data2, &data3, &data4[0],&data4[1], &data4[2], &data4[3],
  &data4[4],&data4[5], &data4[6], &data4[7]))
 {
  return FALSE;
 }


 pGuid->Data1 = data1;
 pGuid->Data2 = (WORD)(data2 & 0xffff);
 pGuid->Data3 = (WORD)(data3 & 0xffff);
 for (i = 0; i < 8; i++)
  pGuid->Data4[i] = (BYTE)(data4[i] & 0xff);


 return TRUE;
}


Enjoy!


Trivia: Maybe you're wondering why I go to all this trouble when I could just swscanf the data directly into the GUID data structure itself.  It turns out the the CE C-Runtime swscanf reads in 4 byte chunks, even on the "0x02".  If you passed in the GUID directly, of particular concern is that swscanf would keep writing past the GUID data structure  itself and smash whatever came after it.  We only want it to write 1 byte (&data4[7]), but it goes 3 more.


[Author: John Spaith]

Comments (1)
  1. gopi says:

    that was very kind of you to share this.  I was pained by not being able to get a guid from a string with a readily available function

Comments are closed.

Skip to main content