123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743 |
- // TestConnIPDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "TestConnIP.h"
- #include "TestConnIPDlg.h"
- #include <afxsock.h>//<Winsock2.h>
- #include "ConnectDlg.h"
- #include "SendDataDlg.h"
- #include "SendReg.h"
- #include <Mmsystem.h>
- #include <afxinet.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #pragma comment(lib, "Winmm.lib")
- #define WM_ICON_NOTIFY WM_USER+12
- DWORD g_nSendCode=0; //g_bSendOK
- /////////////////////////////////////////////////////////////////////////////
- HWND g_hSendWnd;
- extern HWND g_hConnectWnd;
- #define DISCONNECT_TIMER (WM_USER + 101)
- #define LOGINFAILED_TIMER (WM_USER + 102)
- void MyGetIPByName(CString &name)
- {
- CString strIP=name;
- name.Empty ();
- DWORD dwServerIP=0;
- HOSTENT *host = gethostbyname(strIP);
- struct in_addr addr;
- if (host != NULL)
- {
- for(int i = 0; host-> h_addr_list[i] != NULL; i ++)
- {
- memset(&addr, 0, sizeof(addr));
- memcpy(&addr.S_un.S_addr, host-> h_addr_list[i], host-> h_length);
- dwServerIP = ntohl(addr.S_un.S_addr);
- BYTE* pIP = (BYTE*)&dwServerIP;
- name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
- }
- }
- }
- BOOL g_bReturned=0;
- extern DWORD FindAppProcessID(CString path);
- void WriteLogin(CString str)
- {
- CStdioFile fp;
- CString path=g_mainpath+"\\TestConnIP.log";
- if(::PathFileExists (path))
- {
- fp.Open (path, CFile::modeWrite);
- int length=fp.GetLength ();
-
- fp.SeekToEnd ();
- }
- else
- fp.Open (path, CFile::modeCreate|CFile::modeWrite);
- fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
- fp.Close ();
- }
- unsigned __stdcall SendMsgThread(LPVOID lpParam)
- {
- BOOL nNeedConn=1;//信息服务器
- int i;
- CString str,ss;
- BYTE *pData;
- int failconn=0;
- int successconn=0;
-
- int failsend=0;
- int successsend=0;
- while(1)
- {
- ll: if(g_pMainWnd->m_bTerminate)
- break;
- if(1)//nNeedConn)
- {
- if(g_pMainWnd->OnConnect()==0)
- {
- nNeedConn=1;
- ::Sleep (1500);
- failconn++;
- ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d", failconn, successconn, failsend, successsend);
- WriteLogin(ss);
- goto ll;
- }
- else
- {
- successconn++;
- nNeedConn=0;
- ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d", failconn, successconn, failsend, successsend);
- WriteLogin(ss);
- }
- }
-
- str="20111101151606303195.ly.com";
- pData=new BYTE[str.GetLength ()];
- memcpy(pData, str.GetBuffer (0), str.GetLength ());
- str.ReleaseBuffer ();
- EncryptFile2(pData, str.GetLength (), "888666333");
- g_nSendCode=7;
- g_pMainWnd->ProcessChatMessageRequest2(pData, str.GetLength ());
- for(i=0; i<20; i++)
- {
- if(g_bReturned)break;
- ::Sleep (1500);
- }
- delete []pData;g_pMainWnd->OnDisconnect();
- if(g_bReturned==0)
- {
- failsend++;
- nNeedConn=1;
- ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d", failconn, successconn, failsend, successsend);
- WriteLogin(ss);
- goto ll;
- }
- else
- {
- successsend++;
- ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d,%s", failconn, successconn, failsend+failconn, successsend,g_str);
- WriteLogin(ss);
- }
- for(i=0; i<60; i++)
- {
- if(g_pMainWnd->m_bTerminate)break;
- ::Sleep (1000);
- }
- }
- g_pMainWnd->m_bRunning=false;
- g_pMainWnd->m_bTerminate=false;
- _endthreadex( 0 );
- return 0;
- }
- //MessageBox
- /////////////////////////////////////////////////////////////////////////////
- static void HandleClientNetEvent(IN SOCKET hSocket, IN ETransportEvent eEvent,
- IN void *pDataBuf, IN unsigned long nDataLen,
- IN int nError, IN void *pContext)
- {
- if( nError != TRANSPORT_OK ) return;
- CTestConnIPDlg *pDlg = (CTestConnIPDlg *)pContext;
- if( NULL == pDlg ) return;
- pDlg->ProcessNetEvent(eEvent, pDataBuf, nDataLen);
- }
- CTestConnIPDlg::CTestConnIPDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CTestConnIPDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CTestConnIPDlg)
-
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CTestConnIPDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTestConnIPDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CTestConnIPDlg, CDialog)
- //{{AFX_MSG_MAP(CTestConnIPDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_DESTROY()
- ON_WM_TIMER()
- ON_COMMAND(IDM_CLOSE, OnClose)
- ON_COMMAND(IDM_TestConnIP, OnTestConnIP)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- BOOL CTestConnIPDlg::OnInitDialog()
- {
-
- CDialog::OnInitDialog();
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- g_pMainWnd=this;
- SetTimer(1, 10, NULL);
- /////////////////////////////////
- // TODO: Add extra initialization here
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CTestConnIPDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CTestConnIPDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- DWORD CTestConnIPDlg::GetConnectionID()
- {
- return m_dwConnectionID;
- }
- void CTestConnIPDlg::SetConnectionID(DWORD dwConnection)
- {
- m_dwConnectionID = dwConnection;
- }
- void CTestConnIPDlg::ProcessChatMessageRequest2(CString sql)
- {
- const char *szDataBuf = sql.GetBuffer(0);
- sql.ReleaseBuffer();
- ProcessChatMessageRequest((void*)szDataBuf, strlen(szDataBuf) + 1);
- }
- void CTestConnIPDlg::ProcessChatMessageRequest2(BYTE *pData, int length)
- {
- ProcessChatMessageRequest((void*)pData, length);
- }
- BOOL CTestConnIPDlg::ProcessChatMessageRequest(void *szDataBuf, int nDataLen)
- {
- g_bReturned=0;
- DWORD dwFromUserID = GetConnectionID();
- WORD wMessageId = MSG_CHATMESSAGE_REQ;
- DWORD dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen;
- BYTE *pSendData = new BYTE[dwDataLen];
- TCHAT_MESSAGE_STRU *pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
- memset(pChatMessage, 0x00, dwDataLen);
- g_sendhead.length[98]=987123768;
- memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
- pChatMessage->tCommonMsg.dwConnectionID = GetConnectionID();
- pChatMessage->tCommonMsg.wMessageId = wMessageId;
- pChatMessage->dwFromUserID = dwFromUserID;
- pChatMessage->dwToUserID = g_nSendCode;
- pChatMessage->wMessageLen = nDataLen;
- memcpy(pChatMessage->byFileContent, szDataBuf, nDataLen);
-
- TMessageHeader tHeader = {0};
- tHeader.wMessageId = wMessageId;
- tHeader.dwDataLen = dwDataLen;
- BOOL bRet=0;
- unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
- if( ulSendLen != SOCKET_ERROR )
- {
- bRet=1;
- }
- delete [] pSendData;
- return bRet;
- }
- BOOL CTestConnIPDlg::OnConnect()
- {
- g_server="lijiafz.vicp.net" ;
- MyGetIPByName(g_server);
- if(g_server.IsEmpty ())return OnConnect2();
- CString strServerAddress = g_server;
- char *szServerAddress = strServerAddress.GetBuffer(0);
- strServerAddress.ReleaseBuffer();
-
- /*for Client, IP and Port can be 0,
- and for Server, IP is LocalIP, and Port is Listening Port*/
- int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
- 0,
- HandleClientNetEvent,
- this);
- if( TRANSPORT_OK != nResult )
- {
- return 0;
- }
- DWORD dwRemoteIPValue = inet_addr(szServerAddress);
- WORD wPort = GetPort();
- nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
- if( TRANSPORT_OK != nResult )
- {
- m_tClientTunnel.net_CloseSocket();
- return OnConnect2();
- }
- return ProcessLoginRequest();
- }
- BOOL CTestConnIPDlg::OnConnect2()
- {
- CString server="http://www.lyfz.net/download/ip.txt";
- char buf[MAX_PATH];
- ::GetTempPath(sizeof(buf),buf);
- CString m_strTempDir=buf;
- DWORD m_dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
- INTERNET_PORT m_dwPort;
- DWORD dwType;
- CInternetSession m_cis;
- CHttpConnection *m_pHttp;
- CString m_strServer;
- CString m_strIniPath;
- AfxParseURL(server,dwType,m_strServer,m_strIniPath,m_dwPort);
- if(dwType!=AFX_INET_SERVICE_HTTP)
- {
- return OnConnect3();
- }
- m_cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5);
- m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
- try
- {
- m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
- }
- catch(CInternetException* pEx)
- {
- return OnConnect3();
- }
- CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
- m_strIniPath, NULL, 1, NULL, NULL, m_dwHttpRequestFlags);
- try
- {
- pFile->SendRequest();
- }
- catch(CInternetException* pEx)
- {
- pFile->Close();
- return OnConnect3();
- }
- if(pFile)
- {
- CStdioFile csf;
- csf.Open(m_strTempDir+"\\ip.txt",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
- char buf[2048];
- int n;
- while((n=pFile->Read(buf,2048))>0)
- csf.Write(buf,n);
- csf.Close();
- pFile->Close();
- }
- CStdioFile fp;
- fp.Open (m_strTempDir+"\\ip.txt", CFile::modeRead);
- fp.ReadString (g_server);
- fp.Close ();
- CString strServerAddress = g_server;
- char *szServerAddress = strServerAddress.GetBuffer(0);
- strServerAddress.ReleaseBuffer();
-
- /*for Client, IP and Port can be 0,
- and for Server, IP is LocalIP, and Port is Listening Port*/
- int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
- 0,
- HandleClientNetEvent,
- this);
-
- if( TRANSPORT_OK != nResult )
- {
- return 0;
- }
- DWORD dwRemoteIPValue = inet_addr(szServerAddress);
- WORD wPort = GetPort();
- nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
- if( TRANSPORT_OK != nResult )
- {
- m_tClientTunnel.net_CloseSocket();
- return OnConnect3();
- }
- return ProcessLoginRequest();
- }
- BOOL CTestConnIPDlg::OnConnect3()
- {
- CString server="http://photo.bjlyfz.com/download/ip.txt";
- char buf[MAX_PATH];
- ::GetTempPath(sizeof(buf),buf);
- CString m_strTempDir=buf;
- DWORD m_dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
- INTERNET_PORT m_dwPort;
- DWORD dwType;
- CInternetSession m_cis;
- CHttpConnection *m_pHttp;
- CString m_strServer;
- CString m_strIniPath;
- AfxParseURL(server,dwType,m_strServer,m_strIniPath,m_dwPort);
- if(dwType!=AFX_INET_SERVICE_HTTP)
- {
- return FALSE;
- }
- m_cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5);
- m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
- try
- {
- m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
- }
- catch(CInternetException* pEx)
- {
- return false;
- }
- CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
- m_strIniPath, NULL, 1, NULL, NULL, m_dwHttpRequestFlags);
- try
- {
- pFile->SendRequest();
- }
- catch(CInternetException* pEx)
- {
- pFile->Close();
- return false;
- }
- if(pFile)
- {
- CStdioFile csf;
- csf.Open(m_strTempDir+"\\ip.txt",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
- char buf[2048];
- int n;
- while((n=pFile->Read(buf,2048))>0)
- csf.Write(buf,n);
- csf.Close();
- pFile->Close();
- }
- CStdioFile fp;
- fp.Open (m_strTempDir+"\\ip.txt", CFile::modeRead);
- fp.ReadString (g_server);
- fp.Close ();
- CString strServerAddress = g_server;
- char *szServerAddress = strServerAddress.GetBuffer(0);
- strServerAddress.ReleaseBuffer();
-
- /*for Client, IP and Port can be 0,
- and for Server, IP is LocalIP, and Port is Listening Port*/
- int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
- 0,
- HandleClientNetEvent,
- this);
-
- if( TRANSPORT_OK != nResult )
- {
- return 0;
- }
- DWORD dwRemoteIPValue = inet_addr(szServerAddress);
- WORD wPort = GetPort();
- nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
- if( TRANSPORT_OK != nResult )
- {
- m_tClientTunnel.net_CloseSocket();
- return 0;
- }
- return ProcessLoginRequest();
- }
- void CTestConnIPDlg::ProcessNetEvent(int nEventType, void *pRecvMsg, DWORD dwDataLen)
- {
- if( Transport_ReadEv == nEventType )
- {
- if( NULL == pRecvMsg ) return;
- TMessageHeader* pHeader = (TMessageHeader *)pRecvMsg;
- char *pDataBuf = (char *)pRecvMsg + MESSAGE_HEADER_LEN;
- WORD dwMessageID = pHeader->wMessageId;
- switch(dwMessageID)
- {
- case MSG_LOGIN_RESP:
- {
- LOGIN_RESULT_STRU tLoginResult = {0};
- memcpy(&tLoginResult, pDataBuf, sizeof(LOGIN_RESULT_STRU));
-
- ProcessLoginResponse(&tLoginResult);
- break;
- }
- case MSG_USERINFO_RESP:
- {
- TUSERLIST_INFO_STRU tUserListInfo = {0};
- memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
- // ProcessUserListInfoResponse(&tUserListInfo);
- break;
- }
- case MSG_LOGOUT_RESP:
- {
- TUSERLIST_INFO_STRU tUserListInfo = {0};
- memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
- // ProcessLogoutResponse(&tUserListInfo);
- break;
- }
- case MSG_CHATMESSAGE_RESP:
- {
- TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
-
- ProcessChatMessageResponse((void *)pChatMessage);
- break;
- }
- default:
- {
- break;
- }
- }
- }
- else if( Transport_CloseEv == nEventType )
- {
- SetTimer(DISCONNECT_TIMER, 0, NULL);
- }
- ///////
- }
- void CTestConnIPDlg::OnDisconnect()
- {
- m_tClientTunnel.net_CloseSocket();
- SetConnectionID(INVALID_SOCKET);
- }
- void CTestConnIPDlg::ProcessLoginResponse(void *pLoginResult)
- {
- if( NULL == pLoginResult ) return;
- LOGIN_RESULT_STRU *ptLoginResult = (LOGIN_RESULT_STRU *)pLoginResult;
- DWORD dwConnectionID = ptLoginResult->tCommonMsg.dwConnectionID;
- SetConnectionID(dwConnectionID);
- BYTE byResult = ptLoginResult->byResult;
- if(LOGIN_RESULT_SUC == byResult)
- {
- }
- else
- {
- SetTimer(LOGINFAILED_TIMER, 0, NULL);
- }
- CString strCommentInfo("");
- strCommentInfo.Format("%s. 用户代号: %ld",
- ((LOGIN_RESULT_SUC == byResult) ? "登录成功" :
- (LOGIN_RESULT_MULTI == byResult) ? "重复登录" :
- (LOGIN_RESULT_NAMERROR == byResult) ? "名字不存在" :
- (LOGIN_RESULT_PWERROR == byResult) ? "密码错误" : "登录失败"),
- dwConnectionID);
- // MessageBox((CString)strCommentInfo);
- }
- CString newGUID()
- {
- CString str;
- GUID guid;
- // CoInitialize(NULL);
- if (S_OK == ::CoCreateGuid(&guid))
- {
- str.Format (
- "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
- guid.Data1,
- guid.Data2,
- guid.Data3,
- guid.Data4[0], guid.Data4[1],
- guid.Data4[2], guid.Data4[3],
- guid.Data4[4], guid.Data4[5],
- guid.Data4[6], guid.Data4[7]);
- }
- // CoUninitialize();
- return str.Left (28);
- }
- BOOL CTestConnIPDlg::ProcessLoginRequest()
- {
- WORD wMessageId = MSG_LOGIN_REQ;
- TLOGIN_STRU tLogonInfo = {0};
- tLogonInfo.tCommonMsg.dwConnectionID = GetConnectionID();
- tLogonInfo.tCommonMsg.wMessageId = wMessageId;
- CString strUserName = newGUID();
-
- strUserName.TrimLeft();
- strUserName.TrimRight();
- strcpy(tLogonInfo.tUserInfo.szUserName, strUserName);
-
- DWORD dwDataLen = sizeof(TLOGIN_STRU);
- TMessageHeader tHeader = {0};
- tHeader.wMessageId = wMessageId;
- tHeader.dwDataLen = dwDataLen;
- unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)&tLogonInfo, dwDataLen);
- if( ulSendLen == SOCKET_ERROR )
- {
- return 0;
- }
- return 1;
- }
- //---------------------------------------------------------------------------
- void CTestConnIPDlg::OnDestroy()
- {
-
- OnDisconnect();
- Transport_UnInit();
- CDialog::OnDestroy();
- }
- void CTestConnIPDlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- if( DISCONNECT_TIMER == nIDEvent )
- {
- KillTimer(nIDEvent);
- OnDisconnect();
- }
- else if( LOGINFAILED_TIMER == nIDEvent )
- {
- KillTimer(nIDEvent);
- OnDisconnect();
- }
- else if( 1 == nIDEvent )
- {
- KillTimer(1);
-
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bRunning=true;
- m_hThread = (HANDLE)_beginthreadex(NULL,0, SendMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
- }
- }
- void CTestConnIPDlg::OnClose()
- {
- // TODO: Add your command handler code here
- TerminateThread();
- CDialog::OnCancel ();
- }
- BOOL CTestConnIPDlg::TerminateThread()
- {
- try
- {
- if ( !m_bRunning )
- return TRUE;
-
- m_bTerminate=true;
-
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
- break;
-
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread);
- m_bRunning=false;
- return TRUE;
- }
- catch(...)
- {
- }
- }
- CArray<CStringArray, CStringArray>g_List1array;
- DWORD g_nLeng=0;
- BYTE *g_pData=NULL;
- CString g_str="";
- extern BOOL g_bSendData;
- void CTestConnIPDlg::ProcessChatMessageResponse(void *pResponse)
- {
- if( NULL == pResponse ) return;
- TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pResponse;
- int nMessageLen = pChatMessage->wMessageLen;
- DWORD dwToUserID = pChatMessage->dwToUserID;
- // memcpy( &g_sendhead, pChatMessage, sizeof(g_sendhead));
- char *szChatMessage = new char[nMessageLen+1];
- memset(szChatMessage, 0x00, nMessageLen+1);
- memcpy(szChatMessage, pChatMessage->byFileContent, nMessageLen);
- g_str="xx";
- g_str=szChatMessage;
- delete []szChatMessage;
- g_bReturned=1;
- }
-
- BOOL g_bShowDlg=0;
- void CTestConnIPDlg::OnTestConnIP()
- {
- // TODO: Add your command handler code here
-
- }
- int CTestConnIPDlg::GetPort()
- {
- static int aaa=-1;
- if(aaa==-1)
- {
- aaa=CTime::GetCurrentTime ().GetSecond ()%7;
- }
- aaa++;
- if(aaa>=7)aaa=0;
- return 8387+aaa;
- }
|