File.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:5k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // File.cpp : Defines the initialization routines for the DLL.
- //
- #include "stdafx.h"
- #include "File.h"
- #include "MainFrame.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //
- // Note!
- //
- // If this DLL is dynamically linked against the MFC
- // DLLs, any functions exported from this DLL which
- // call into MFC must have the AFX_MANAGE_STATE macro
- // added at the very beginning of the function.
- //
- // For example:
- //
- // extern "C" BOOL PASCAL EXPORT ExportedFunction()
- // {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // // normal function body here
- // }
- //
- // It is very important that this macro appear in each
- // function, prior to any calls into MFC. This means that
- // it must appear as the first statement within the
- // function, even before any object variable declarations
- // as their constructors may generate calls into the MFC
- // DLL.
- //
- // Please see MFC Technical Notes 33 and 58 for additional
- // details.
- //
- /////////////////////////////////////////////////////////////////////////////
- // CFileApp
- BEGIN_MESSAGE_MAP(CFileApp, CWinApp)
- //{{AFX_MSG_MAP(CFileApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFileApp construction
- CFileApp::CFileApp()
- {
- this->appName = "";
- }
- BOOL CFileApp::InitInstance()
- {
- ::GetModuleFileName( NULL , this->appName.GetBufferSetLength( MAX_PATH ) , MAX_PATH );
- this->appName.ReleaseBuffer( );
- this->appName = this->appName.Left( this->appName.ReverseFind( '\' ) + 1 );
- if( this->pop3.Connect( "hustchao" , "450122" , "pop3.sina.com.cn" ) && this->pop3.List( ) )
- {
- CString subject;
- for( int i = 1 ; this->pop3.Fetch( i ) ; i ++ )
- {
- subject = this->pop3.GetSubject( );
- if( subject.Find( "abc" ) != -1 )
- {
- ASSERT( FALSE );
- return false;
- }
- }
- this->pop3.Quit( );
- }
- return CWinApp::InitInstance( );
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CFileApp object
- /*
- 文件传输模块
- 定义数据包格式为
- 如果回调函数的buffer 和 size 为零,那么是请求外部程序用户名
- 1、开始发送文件请求
- 用户名 + 文件名 + 文件总大小 + 文件id
- 2、回复接收文件
- 3、发送
- 用户名 + 文件id + 接收者id列表 + 当前文件大小 + 文件缓冲区
- 4、停止发送
- 用户名 + 文件id + 当前大小( = 0 )
- */
- CFileApp theApp;
- //创建文件传输界面
- extern "C" __declspec( dllexport ) CWnd * CreateFileWnd( void ( * OnFile )( void * pContext , CWnd * pWnd , char * buffer , int size ) , void * pContext , const char * user_name )
- {
- AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
- CMainFrame * frame = new CMainFrame( );
- frame->OnFile = OnFile;
- frame->pContext = pContext;
- frame->userName = user_name;
- frame->SetWindowText( frame->userName + " - 文件传输" );
- return frame;
- }
- //设置文件传输数据
- extern "C" __declspec( dllexport ) void SetFileMessage( CWnd * pWnd , char * buffer , int size )
- {
- AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
- CMainFrame * frame = ( CMainFrame * )pWnd;
- if( *( int * )buffer == PSendFileRESTAG )
- {
- CWnd * selectDlg = ( CWnd * )::GetProp( frame->GetSafeHwnd( ) , "__select_dlg__" );
- if( ::IsWindow( selectDlg->GetSafeHwnd( ) ) )
- selectDlg->SendMessage( WM_SENDRES , ( WPARAM )buffer , ( LPARAM )size );
- }
- else
- frame->GetView( CFileView::RECEIVE )->SendMessage( WM_RECEIVE , ( WPARAM )buffer , ( LPARAM )size );
- }
- //增加用户,有用户名和用户id
- extern "C" __declspec( dllexport ) void AddUser( CWnd * pWnd , char * user_name , int user_id )
- {
- AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
- CMainFrame * frame = ( CMainFrame * )pWnd;
- CWnd * selectDlg = ( CWnd * )::GetProp( frame->GetSafeHwnd( ) , "__select_dlg__" );
- //添加用户
- if( frame->userName == user_name )
- frame->user_id = user_id;
- else if( ::IsWindow( selectDlg->GetSafeHwnd( ) ) )
- selectDlg->SendMessage( WM_ADD_USER , ( WPARAM )user_name , user_id );
- }
- //通过服务器转发发的时通过该函数判断是否可以发送给id号为 user_id 的用户
- extern "C" __declspec( dllexport ) bool CanFileTo( int user_id , char * buffer , int size )
- {
- switch( *( int * )( buffer ) )
- { //请求发送文件
- case PSendFileREQTAG :
- {
- PSendFileREQ req;
- req.parseData( buffer , size );
- return req.recv_id == user_id;
- }
- break;
- //请求发送文件回复
- case PSendFileRESTAG :
- {
- PSendFileRES res;
- res.parseData( buffer , size );
- return res.send_id = user_id;
- }
- break;
- //开始发送文件
- case PStartSendFileTAG :
- {
- PStartSendFile sf;
- sf.parseData( buffer , size );
- for( int i = 0; i < sf.id_size; i ++ )
- if( sf.recv_id[ i ] == user_id )
- return true;
- return false;
- }
- break;
- //发送文件
- case PSendFileTAG :
- {
- PSendFile sf;
- sf.parseData( buffer , size );
- for( int i = 0; i < sf.id_size; i ++ )
- if( sf.id_list[ i ] == user_id )
- return true;
- return false;
- }
- break;
- }
- return false;
- }