CONVERT_STR_2_GUID 方法一:
#define CONVERT_STR_2_GUID(cstr, stGuid) do\
{\
swscanf_s((const wchar_t*)cstr, L"{%8x-%4x-%4x-%2x%2x-%2x%2x%2x%2x%2x%2x}",\
&(stGuid.Data1),&(stGuid.Data2),&(stGuid.Data3),\
&(stGuid.Data4[0]),&(stGuid.Data4[1]),&(stGuid.Data4[2]),&(stGuid.Data4[3]),\
&(stGuid.Data4[4]),&(stGuid.Data4[5]),&(stGuid.Data4[6]),&(stGuid.Data4[7]));\
}while(0);
方法二(新):1.在{}带空格容错处理上,2.在非法字符退出,有更好表现,不引起内容读取非法和字符非法上的出错
inline int CONVERT_STR_2_GUID(const unsigned char*cstr, GUID *pGuid)
{
if (pGuid == NULL || cstr == NULL)return -1;
unsigned char *pTemp = (unsigned char *)strchr( (char *)cstr,'{');
if (pTemp == NULL )return -1;
unsigned char *pEnd = (unsigned char *)strchr((char *)pTemp, '}');
if (pTemp == NULL || pEnd == NULL|| pEnd-pTemp<=35)