#include 提示,无法打开源文件。MSGQUEUEOPTIONS显示未定义标识符,该如何解决
#include <msgqueue.h>提示,无法打开源文件。MSGQUEUEOPTIONS显示未定义标识符
想做做关于消息队列的例子看看,结果竟错误,用的VS2010.
提示未定义标识符[img=http://hi.****.net/attachment/201203/21/6081471_1332294896yR97.png][/img]
提示无法打开源文件"msgqueue.h"[img=http://hi.****.net/attachment/201203/21/6081471_1332294887F7z0.png][/img]
各位大侠,怎么办啊???
源代码如下:
想做做关于消息队列的例子看看,结果竟错误,用的VS2010.
提示未定义标识符[img=http://hi.****.net/attachment/201203/21/6081471_1332294896yR97.png][/img]
提示无法打开源文件"msgqueue.h"[img=http://hi.****.net/attachment/201203/21/6081471_1332294887F7z0.png][/img]
各位大侠,怎么办啊???
源代码如下:
- C/C++ code
#include <windows.h> #include <stdio.h> #include <process.h> #include <iostream> #include <msgqueue.h> using namespace std; HANDLE hReadMsgQueue; HANDLE hWriteMsgQueue; const TCHAR szevtWriteComMsgQueue[] = TEXT("WriteComMsgQueue"); //写消息队列 const TCHAR szevtReadComMsgQueue[] = TEXT("ReadComMsgQueue"); //读消息对列 void InitCommMsgQueue(void) //2009--9--29 xqh 初始化系统用到的消息队列 { MSGQUEUEOPTIONS options = {0}; options.dwSize = sizeof(MSGQUEUEOPTIONS); options.dwFlags = 0; //options.dwMaxMessages = QUEUE_ENTRIES; //options.cbMaxMessage = sizeof(POWER_BROADCAST)+MAX_NAMELEN; options.dwMaxMessages=1; options.cbMaxMessage=10; options.bReadAccess=TRUE; //options.bReadAccess=FALSE; hReadMsgQueue=CreateMsgQueue(szevtWriteComMsgQueue,&options); //2009--9--29 XQH 读写的消息句柄是不相同的!!! if(hReadMsgQueue==NULL) RETAILMSG(1,(TEXT("[BSP]++++1111::InitCommMsgQueue( )----in failure/r/n"))); else RETAILMSG(1,(TEXT("[BSP]++++1111::InitCommMsgQueue( )----in success/r/n"))); RETAILMSG(1,(TEXT("[BSP]++++1111-1::InitCommMsgQueue( )----the hReadMsgQueue is 0x%x/r/n"),hReadMsgQueue)); //-------------------------------------------- //MSGQUEUEOPTIONS options = {0}; options.dwSize = sizeof(MSGQUEUEOPTIONS); options.dwFlags = 0; //options.dwMaxMessages = QUEUE_ENTRIES; //options.cbMaxMessage = sizeof(POWER_BROADCAST)+MAX_NAMELEN; options.dwMaxMessages=1; options.cbMaxMessage=10; // options.bReadAccess=TRUE; options.bReadAccess=FALSE; hWriteMsgQueue=CreateMsgQueue(szevtReadComMsgQueue,&options);//2009--9--29 XQH 读写的消息句柄是不相同的!!! if(hWriteMsgQueue==NULL) RETAILMSG(1,(TEXT("[BSP]++++2222::InitCommMsgQueue( )----in failure/r/n"))); else RETAILMSG(1,(TEXT("[BSP]++++2222::InitCommMsgQueue( )----in success/r/n"))); RETAILMSG(1,(TEXT("[BSP]++++2222-1::InitCommMsgQueue( )----the hWriteMsgQueue is 0x%x/r/n"),hWriteMsgQueue)); } void WriteMsgQueue(void) { int i; BYTE tempByte[10]; for(i=0;i<10;i++) { tempByte[i]=0x30+i; } DWORD dwTimeout=INFINITE; //DWORD dwFlags=MSGQUEUE_MSGALERT ; //警告消息 DWORD dwFlags=2; BOOL bRet; if(hReadMsgQueue==NULL) RETAILMSG(1,(TEXT("[BSP]++++WriteMsgQueue( )----the hReadMsgQueue is NULL/r/n"))); if(hWriteMsgQueue==NULL) RETAILMSG(1,(TEXT("[BSP]++++WriteMsgQueue( )----the hWriteMsgQueue is NULL/r/n"))); // bRet=WriteMsgQueue(hReadMsgQueue, tempByte,10,dwTimeout,dwFlags); bRet=WriteMsgQueue(hWriteMsgQueue, tempByte,10,dwTimeout,dwFlags); DWORD dwError; dwError=GetLastError( ); //句柄无效??? RETAILMSG(1,(TEXT("[BSP]++++WriteMsgQueue( )----the dwError is 0x%x/r/n"),dwError)); if(bRet) RETAILMSG(1,(TEXT("[BSP]++++WriteMsgQueue( )----in success/r/n"))); else RETAILMSG(1,(TEXT("[BSP]++++WriteMsgQueue( )----in failure/r/n"))); } DWORD WaitMsgQueueThread(LPVOID lparam) { int i; unsigned long nRead = 0, flags = 0, res = 0; BYTE ByteBuf[10]; RETAILMSG(1,(TEXT("[BSP]++++WaitMsgQueueThread( )----Running/r/n"))); while(1) { DWORD dwRes = WaitForSingleObject(hReadMsgQueue,INFINITE); // DWORD dwRes = WaitForSingleObject(hWriteMsgQueue,INFINITE); if(dwRes==WAIT_OBJECT_0) { RETAILMSG(1,(TEXT("[BSP]++++WaitMsgQueueThread( )----/r/n"))); memset(&ByteBuf, 0, 10); if (ReadMsgQueue(hReadMsgQueue, &ByteBuf, 10, &nRead, INFINITE, &flags)) { for(i=0;i<nRead;i++) { RETAILMSG(1,(TEXT("[BSP]++++WaitMsgQueueThread( )----the index is %d,the data is 0x%x/r/n"),i,ByteBuf[i])); } } }// if(dwRes==WAIT_OBJECT_0) }//while(1) return 0; }