查询CTL_CODE

#define CTL_CODE( DeviceType, Function, Method, Access ) (                 \
	((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
	)


int strToInt(char* str)
{
	int		i							= 0;
	int		differ						= 0;
	int		code						= 0;
	int		tmpCode						= 0;
	bool	bResult						= false;


	__try
	{
		if (!str)
		{
			printf("[strtoint] : input parameter error. (str : 0x%08p) \n", str);
			__leave;
		}

		for (i = 0; i < 8; i++)
		{
			differ = *(str + i) - '0';

			if ((differ >= 0) && (differ <= 9))
			{
				;
			}
			else if ((differ >= 17) && (differ <= 22))
			{
				differ -= ('A' - '9');
				differ++;
			}
			else if ((differ >= 49) && (differ <= 54))
			{
				differ -= ('a' - '9');
				differ++;
			}
			else
			{
				printf("[strtoint] : illegal character. (str : %s) \n", str);
				__leave;
			}

			tmpCode = code>>(4 * (7 - i));

			while (differ--)
				tmpCode += 0x1;

			code |= tmpCode<<(4 * (7 - i));

			tmpCode = 0;
		}

		bResult = true;
	}
	__finally
	{
		if (!bResult)
			code = 0;
	}

	return code;
}

int _tmain(int argc, _TCHAR* argv[])
{
	char	chCode[9 * sizeof(char)]	= {0};
	int		code						= 0;


 	scanf("%s", chCode); 
	code = strToInt(chCode);
 	printf("code \t\t : 0x%08x \n", code);
 	printf("DeviceType \t : %04x \n", (code >> 16) & 0x0000ffff);
 	printf("Function \t : %03x \n", (code >> 2) & 0x00000fff);
 	printf("Method \t\t : %01x \n", code & 0x000003);
 	printf("Access \t\t : %01x \n", (code >> 14) & 0x000003);


	getch();

	return 0;
}

你可能感兴趣的:(查询CTL_CODE)