Visual C++ serial communication 的问题,请高手指点,多谢用的是nonoverlap,m_hcomm的createfile和DCBconfigration都没有错,就是在writefile的时候:
unsigned long dwNumberOfBytesSent = 1;
char * pszBuf="test";
DWORD dwSize=4;
while(dwNumberOfBytesSent < dwSize)
{
unsigned long dwNumberOfBytesWritten;
if((WriteFile(m_hComm, &pszBuf[dwNumberOfBytesSent], 1, &dwNumberOfBytesWritten, NULL)) != 0)
{
if(dwNumberOfBytesWritten > 0)
++dwNumberOfBytesSent;
else{
printf("writing fail!\n");
return 0;
}
}
else
{
printf("writing fail!\n");
printf("%d\n",GetLastError());
return 0;
}
printf("%d byte sent\n", dwNumberOfBytesSent);
}
getlasterror()是87, parameter pass error。我觉得是pszBuf 的问题。难道不能用char *?但是我试了其他几种format都不行。请问有没有做过类似application的同志来指点一下?
十分感谢。[柳五 (3-9 23:33, Long long ago)]
[ 传统版 |
sForum ][登录后回复]1楼