ÏûÏ¢¶ÓÁÐÒ²ÊÇÓÃÓÚ´«µÝÏûÏ¢£¨±äÁ¿¡¢Êý×é¡¢½á¹¹Ìå¡¢Ö¸Õ룩¡£ºÃ´¦£ºÓжà¸öÏûÏ¢»º³åÇø£¬¿ÉÒÔʵÏÖÏȽøÏȳö£¨Ë®¹Ü£©¡£
1.1 È«¾ÖÖ¸ÕëÊý×é´«µÝ¶àÔòÏûÏ¢#include <stdio.h> void postMessageQueue(void** pMsgQueue); void *msgQueue[10]; //Ö¸ÕëÊý×飬10¸öÔªËØ£¬Ã¿¸öÔªËض¼ÊÇÒ»¸övoid*ÀàÐ͵ÄÖ¸Õë void main() { unsigned char buf[2] = {0,1}; //¶¨ÒåÒ»¸öÊý×é msgQueue[0] = (void*)buf; //½«Êý×é buf ¸³Öµ ¸øÖ¸ÕëÊý×émsgQueueµÄÔªËØ0£¬×¢Ò⣺Êý×éÃûÊÇÖ¸Õ룬ÐèҪǿÖÆ»»Îªvoid*ÀàÐÍ postMessageQueue(&msgQueue[0]); //´«µÝÖ¸ÕëÊý×émsgQueueµÄÊ×µØÖ·À´´«µÝÕû¸öÖ¸ÕëÊý×é } void postMessageQueue(void** pMsgQueue) { unsigned char *pBuf; //¶¨ÒåÒ»¸öÖ¸Õ룬ÀàËÆΪunsigned char * pBuf = (unsigned char *)pMsgQueue[0]; //È¡³öÖ¸ÕëÊý×éµÄÔªËØ0£¬²¢Ç¿ÖÆת»»Îªunsigned char *µÄÖ¸Õë printf("%d\r\n",pBuf[0]); //pBufÖ¸Õëbuf£¬pBuf[0] ÊÇ0 printf("%d\r\n",pBuf[1]); //pBufÖ¸Õëbuf£¬pBuf[1] ÊÇ1 } |
Ö¸ÕëÊý×é´«µÝÏûÏ¢¿ÉÒÔʵÏÖÒ»´ÎÐÔ´«µÝ¶àÔòÏûÏ¢¡£¾ÙÀý£º
#include <stdio.h> void postMessageQueue(void** pMsgQueue); void *msgQueue[10]; //Ö¸ÕëÊý×飬10¸öÔªËØ£¬Ã¿¸öÔªËض¼ÊÇÒ»¸övoid*ÀàÐ͵ÄÖ¸Õë void main() { unsigned char buf[2] = {0,1}; //¶¨ÒåÒ»¸öÊý×é float data = 6.666; int buf1[3] = {55555,66666,88888}; msgQueue[0] = (void*)buf; //½«Êý×é buf ¸³Öµ ¸øÖ¸ÕëÊý×émsgQueueµÄÔªËØ0£¬×¢Ò⣺Êý×éÃûÊÇÖ¸Õ룬ÐèҪǿÖÆ»»Îªvoid*ÀàÐÍ msgQueue[1] = (void*)&data; msgQueue[2] = (void*)buf1; postMessageQueue(&msgQueue[0]); //´«µÝÖ¸ÕëÊý×émsgQueueµÄÊ×µØÖ·À´´«µÝÕû¸öÖ¸ÕëÊý×é } void postMessageQueue(void** pMsgQueue) { unsigned char *pBuf; //¶¨ÒåÒ»¸öÖ¸Õ룬ÀàËÆΪunsigned char * float *pData; int *pBuf1; pBuf = (unsigned char *)pMsgQueue[0]; //È¡³öÖ¸ÕëÊý×éµÄÔªËØ0£¬²¢Ç¿ÖÆת»»Îªunsigned char *µÄÖ¸Õë printf("%d\r\n",pBuf[0]); //pBufÖ¸Õëbuf£¬pBuf[0] ÊÇ0 printf("%d\r\n",pBuf[1]); //pBufÖ¸Õëbuf£¬pBuf[1] ÊÇ1 pData = (float*)pMsgQueue[1]; printf("%f\r\n",*pData); pBuf1 = (int*)pMsgQueue[2]; printf("%d\r\n",pBuf1[0]); printf("%d\r\n",pBuf1[1]); printf("%d\r\n",pBuf1[2]); } |