另外,句柄hComm,在关闭后,我没delete,而是hComm=0;这样可以么?

解决方案 »

  1.   

    hComm=CreateFile("COM1",GENERIC_READ|GENERIC_WRITE,0,NULL,
                         OPEN_EXISTING,0, NULL);
    DCB dcb;
    GetCommState(hComm[i],&dcb);
    dcb.BaudRate=CBR_9600;
    dcb.Parity=EVENPARITY;
    dcb.ByteSize=8;
    dcb.StopBits=TWOSTOPBITS;
    SetCommState(hComm[i],&dcb);
    SetupComm(hComm[i],1024,1024);
      

  2.   

    程序报错,MFC42D.DLL中,无法得到句柄。但是,有时还可以带开船口,奇怪!
      

  3.   

    GetCommState(hComm[i],&dcb);
                       ^这是啥子意思?VC中的例子:DCB dcb;
    HANDLE hCom;
    DWORD dwError;
    BOOL fSuccess;hCom = CreateFile( "COM1",
        GENERIC_READ | GENERIC_WRITE,
        0,    // comm devices must be opened w/exclusive-access 
        NULL, // no security attributes 
        OPEN_EXISTING, // comm devices must use OPEN_EXISTING 
        0,    // not overlapped I/O 
        NULL  // hTemplate must be NULL for comm devices 
        );if (hCom == INVALID_HANDLE_VALUE) 
    {
        dwError = GetLastError();    // handle error 
    }// Omit the call to SetupComm to use the default queue sizes.
    // Get the current configuration.fSuccess = GetCommState(hCom, &dcb);if (!fSuccess) 
    {
        // Handle the error. 
    }// Fill in the DCB: baud=9600, 8 data bits, no parity, 1 stop bit. dcb.BaudRate = 9600;
    dcb.ByteSize = 8;
    dcb.Parity = NOPARITY;
    dcb.StopBits = ONESTOPBIT;fSuccess = SetCommState(hCom, &dcb);if (!fSuccess) 
    {
        // Handle the error. 
    }