第一次用 VC 不熟悉  调试下面程序有问题 望能指教void CCommonDlg::Onpara() // 读24c16 里的网络参数;
{
OVERLAPPED osWrite = {0};
    DWORD dwWritten;
DWORD dwRes;
//OVERLAPPED osReader = {0};
DWORD dwRead;
int b[18];
int a[18];
a[0]=0x3e;
a[1]=0x04;
osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
         if (osWrite.hEvent == NULL)   return;
         WriteFile(hComm, a, 18, &dwWritten, &osWrite);

int aaa=GetLastError();  // aaa 错误代号为 997为何 WriteFile  函数写不进?  

解决方案 »

  1.   

    // 997 是 ERROR_IO_PENDING
    if (aaa == ERROR_IO_PENDING) 
        if ( GetOverlappedResult(hComm, &osWrite, &dwWritten, TRUE) ) 
            // OK
        else 
            // Error
      

  2.   

    int aaa=GetLastError();  // aaa 错误代号为 997这是 为了知道 到底 什么错了  查了 997 的 错误说明 楼上说的  不是很明白?俺贴的 代码  如何 才能 写串口参数 成功?谢谢
      

  3.   

    void CCommonDlg::Onpara() // 读24c16 里的网络参数;
    {
    // TODO: Add your control notification handler code here
    OVERLAPPED osWrite = {0};
        DWORD dwWritten;
    DWORD dwRes;
    //OVERLAPPED osReader = {0};
    DWORD dwRead;
    int b[18];
    int a[18];
    a[0]=0x3e;
    a[1]=0x04;
    osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
       if (osWrite.hEvent == NULL)   return;
        WriteFile(hComm, a, 18, &dwWritten, &osWrite);
    if ( GetOverlappedResult(hComm, &osWrite, &dwWritten, TRUE) ) 

    123 AfxMessageBox ("ok");  //这里显示成功了  就是说发下去的
                                             // 命令成功 即 0x3E 0x04
    }// OK
        else 
    {
    AfxMessageBox ("error");
    }


       这个函数ReadFile(hComm, b, 18, &dwRead, &osReader);
     既 收  24c16里的 参数 这么写对不? 放 123 处么?
    见笑啦   第一次用VC   

    }
      

  4.   

    BOOL bRet = WriteFile(hComm, a, 18, &dwWritten, &osWrite);
    if ( !bRet ) {
        iError = GetLastError();
        if ( iError == ERROR_IO_PENDING ) {
            bRet = GetOverlappedResult(hComm, &osWrite, &dwWritten, TRUE);
        }
    }if ( bRet ) {  // 发送成功
        COMSTAT stComStat;
        DWORD dwErrorFlag;
        ClearCommError(hComm, &dwErrorFlag, &stComStat);
        if ( stComStat.cbInQue > 0 ) { // 串口有数据
            bRet = ReadFile(hComm, b, 18, &dwRead, &osReader);
            if ( bRet ) {
                bRet = GetOverlappedResult(hComm, &osReader, &dwRead, FALSE);
            }
        }
    }