创建C++线程

来源:互联网 发布:赵j家人 知乎 编辑:程序博客网 时间:2024/05/21 14:48
创建C++线程
#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  
        (LPTHREAD_START_ROUTINE)ThreadFunc,                  // thread function 
        NULL,                // 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 );
   }

}
原创粉丝点击