我现在一个程序 需要实现8个串口同时通讯 而且彼此不影响
有人告诉我需要用多线程来实现
但本人从来没有用过
求个相关例程来研究下

解决方案 »

  1.   

    #include <windows.h>
    #include <conio.h>DWORD WINAPI ThreadFunc( LPVOID lpParam ) 

        char szMsg[80];    wsprintf( szMsg, "Parameter = %d.", *(DWORD*)lpParam ); 
        MessageBox( NULL, szMsg, "ThreadFunc", MB_OK );    return 0; 

     
    VOID main( VOID ) 

        DWORD dwThreadId, dwThrdParam = 1; 
        HANDLE hThread; 
        char szMsg[80];    hThread = CreateThread( 
            NULL,                        // default security attributes 
            0,                           // use default stack size  
            ThreadFunc,                  // thread function 
            &dwThrdParam,                // argument to thread function 
            0,                           // use default creation flags 
            &dwThreadId);                // returns the thread identifier 
     
       // Check the return value for success. 
     
       if (hThread == NULL) 
       {
          wsprintf( szMsg, "CreateThread failed." ); 
          MessageBox( NULL, szMsg, "main", MB_OK );
       }
       else 
       {
          _getch();
          CloseHandle( hThread );
       }
    }