使用WriteFile GetLastError的返回值是5,怎么提升权限
答案:2 悬赏:30
解决时间 2021-12-28 19:10
- 提问者网友:傀儡离开
- 2021-12-27 19:50
使用WriteFile GetLastError的返回值是5,怎么提升权限
最佳答案
- 二级知识专家网友:一个很哇塞的汉子
- 2021-12-27 20:38
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;
全部回答
- 1楼网友:努力只為明天
- 2021-12-27 22:17
额,不知道bool writefile( handle hfile, // 文件句柄 lpcvoid lpbuffer, // 数据缓存区指针 dword nnumberofbytestowrite, // 你要写的字节数 lpdword lpnumberofbyteswritten, // 用于保存实际写入字节数的存储区域的指针
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯