使用WriteFile GetLastError的返回值是5,怎么提升权限
1个回答
展开全部
ComHandle=CreateFile(Port,
GENERIC_READ||GENERIC_WRITE,
0,NULL,OPEN_EXISTING,NULL,NULL);
if(ComHandle==INVALID_HANDLE_VALUE){MessageBox("1"); return 0;}
char tmpP[11]="9600,n,8,1";//设置通讯参数
DCB dcb;
if(GetCommState(ComHandle,&dcb)==0){MessageBox("2");return -1;}
if(BuildCommDCB(tmpP,&dcb)==0){MessageBox("3");return -1;}
if(SetCommState(ComHandle,&dcb)==0){MessageBox("4");return -1;}
COMMTIMEOUTS TimeOuts;//设置超时时间
GetCommTimeouts(ComHandle,&TimeOuts);
TimeOuts.ReadIntervalTimeout=2000;
TimeOuts.ReadTotalTimeoutConstant=400;
TimeOuts.ReadTotalTimeoutMultiplier=400;
TimeOuts.WriteTotalTimeoutMultiplier=40;
TimeOuts.WriteTotalTimeoutConstant=400;
if(SetCommTimeouts(ComHandle,&TimeOuts)==0){MessageBox("6");return -2;}
if(SetupComm(ComHandle,2048,1024)==0){MessageBox("7");return -3;}//设置缓冲区
//PurgeComm(ComHandle,PURGE_RXABORT||PURGE_RXCLEAR);
//PurgeComm(ComHandle,PURGE_TXABORT||PURGE_TXCLEAR);
if(ComHandle<0){MessageBox("111");return 111;}
BYTE m_SendBuffer[1];
DWORD m_Number;
m_SendBuffer[0]=0x06;
if(WriteFile(ComHandle, m_SendBuffer, 1 , &m_Number,NULL)==0)
{
DWORD ErrorCode;
ErrorCode=GetLastError();
char temp[5];
sprintf(temp,"%d",ErrorCode);
MessageBox(temp);
MessageBox("here!");
return -5;
}
CloseHandle(ComHandle);
// Write();
MessageBox(Port);
return 0;
GENERIC_READ||GENERIC_WRITE,
0,NULL,OPEN_EXISTING,NULL,NULL);
if(ComHandle==INVALID_HANDLE_VALUE){MessageBox("1"); return 0;}
char tmpP[11]="9600,n,8,1";//设置通讯参数
DCB dcb;
if(GetCommState(ComHandle,&dcb)==0){MessageBox("2");return -1;}
if(BuildCommDCB(tmpP,&dcb)==0){MessageBox("3");return -1;}
if(SetCommState(ComHandle,&dcb)==0){MessageBox("4");return -1;}
COMMTIMEOUTS TimeOuts;//设置超时时间
GetCommTimeouts(ComHandle,&TimeOuts);
TimeOuts.ReadIntervalTimeout=2000;
TimeOuts.ReadTotalTimeoutConstant=400;
TimeOuts.ReadTotalTimeoutMultiplier=400;
TimeOuts.WriteTotalTimeoutMultiplier=40;
TimeOuts.WriteTotalTimeoutConstant=400;
if(SetCommTimeouts(ComHandle,&TimeOuts)==0){MessageBox("6");return -2;}
if(SetupComm(ComHandle,2048,1024)==0){MessageBox("7");return -3;}//设置缓冲区
//PurgeComm(ComHandle,PURGE_RXABORT||PURGE_RXCLEAR);
//PurgeComm(ComHandle,PURGE_TXABORT||PURGE_TXCLEAR);
if(ComHandle<0){MessageBox("111");return 111;}
BYTE m_SendBuffer[1];
DWORD m_Number;
m_SendBuffer[0]=0x06;
if(WriteFile(ComHandle, m_SendBuffer, 1 , &m_Number,NULL)==0)
{
DWORD ErrorCode;
ErrorCode=GetLastError();
char temp[5];
sprintf(temp,"%d",ErrorCode);
MessageBox(temp);
MessageBox("here!");
return -5;
}
CloseHandle(ComHandle);
// Write();
MessageBox(Port);
return 0;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询