×

多线程与聊天室程序的创建

消耗积分:1 | 格式:rar | 大小:35KB | 2017-05-16

雪生1

分享资料个

多线程程序的编写,多线程应用中容易出现的问题。互斥对象的讲解,如何采用互斥对象来实现多线程的同步。如何利用命名互斥对象保证应用程序只有一个实例运行。应用多线程编写网络聊天室程序。

  // Chat.cpp : Defines the class behaviors for the application.

  //

  #include “stdafx.h”

  #include “Chat.h”

  #include “ChatDlg.h”

  #ifdef _DEBUG

  #define new DEBUG_NEW

  #undef THIS_FILE

  static char THIS_FILE[] = __FILE__;

  #endif

  /////////////////////////////////////////////////////////////////////////////

  // CChatApp

  BEGIN_MESSAGE_MAP(CChatApp, CWinApp)

  //{{AFX_MSG_MAP(CChatApp)

  // NOTE - the ClassWizard will add and remove mapping macros here.

  // DO NOT EDIT what you see in these blocks of generated code!

  //}}AFX_MSG

  ON_COMMAND(ID_HELP, CWinApp::OnHelp)

  END_MESSAGE_MAP()

  /////////////////////////////////////////////////////////////////////////////

  // CChatApp construction

  CChatApp::CChatApp()

  {

  // TODO: add construction code here,

  // Place all significant initialization in InitInstance

  }

  /////////////////////////////////////////////////////////////////////////////

  // The one and only CChatApp object

  CChatApp theApp;

  /////////////////////////////////////////////////////////////////////////////

  // CChatApp initialization

  BOOL CChatApp::InitInstance()

  {

  if(!AfxSocketInit())

  {

  AfxMessageBox(“加载套接字库失败!”);

  return FALSE;

  }

  AfxEnableControlContainer();

  // Standard initialization

  // If you are not using these features and wish to reduce the size

  // of your final executable, you should remove from the following

  // the specific initialization routines you do not need.

  #ifdef _AFXDLL

  Enable3dControls(); // Call this when using MFC in a shared DLL

  #else

  Enable3dControlsStatic(); // Call this when linking to MFC statically
多线程与聊天室程序的创建
 

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !