51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2295|回复: 1
打印 上一主题 下一主题

性能测试工具源代码 as400

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2014-4-7 11:15:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
完整代码在CSDN上,我在这里只将其中部分代码,贴出来。
完整代码路径:
http://download.csdn.net/detail/qsword/7004497

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

#include "stdafx.h"
#include "TCPServer.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "TCPServerDoc.h"
#include "TCPServerView.h"
#include "SetPortDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

HINSTANCE hDll;                        //DLL句柄
lpDLLFun_EtoANP EtoANP; //函数指针


/////////////////////////////////////////////////////////////////////////////
// CTCPServerApp

BEGIN_MESSAGE_MAP(CTCPServerApp, CWinApp)
        //{{AFX_MSG_MAP(CTCPServerApp)
        ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
                // 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
        // Standard file based document commands
        ON_COMMAND(ID_FILE_NEW, CTCPServerApp::OnFileNew)
//        ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTCPServerApp construction

CTCPServerApp::CTCPServerApp()
{
        // TODO: add construction code here,
        // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTCPServerApp object

CTCPServerApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CTCPServerApp initialization

BOOL CTCPServerApp::InitInstance()
{
        //禁止运行应用程序的多个实例
        HANDLE        hMutexOneInstance;
        hMutexOneInstance = ::CreateMutex(NULL, FALSE, "OnlyOneInstance_PacketRecvCardAgent");
        if (GetLastError() == ERROR_ALREADY_EXISTS)  return FALSE;

        //设置本进程为实时优先级
        ::SetPriorityClass( ::GetCurrentProcess(), REALTIME_PRIORITY_CLASS );

        //WinSock初始化
        if (!AfxSocketInit())
        {
                AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
                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
#endif

        // Change the registry key under which our settings are stored.
        // TODO: You should modify this string to be something appropriate
        // such as the name of your company or organization.
        SetRegistryKey(_T("Local AppWizard-Generated Applications"));

        LoadStdProfileSettings();  // Load standard INI file options (including MRU)

        // Register the application's document templates.  Document templates
        //  serve as the connection between documents, frame windows and views.

        m_pDocTemplate0 = new CMultiDocTemplate(
                IDR_RECVPACKET,
                RUNTIME_CLASS(CTCPServerDoc),
                RUNTIME_CLASS(CChildFrame),
                RUNTIME_CLASS(CTCPServerView));
        AddDocTemplate(m_pDocTemplate0);
        m_pDocTemplate1 = new CMultiDocTemplate(
                IDR_RECVCARD,
                RUNTIME_CLASS(CTCPServerDoc),
                RUNTIME_CLASS(CChildFrame),
                RUNTIME_CLASS(CTCPServerView));
        AddDocTemplate(m_pDocTemplate1);
        m_pDocTemplate2 = new CMultiDocTemplate(
                IDR_RECVAGENT,
                RUNTIME_CLASS(CTCPServerDoc),
                RUNTIME_CLASS(CChildFrame),
                RUNTIME_CLASS(CTCPServerView));
        AddDocTemplate(m_pDocTemplate2);

        // create main MDI Frame window
        CMainFrame* pMainFrame = new CMainFrame;
        if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
                return FALSE;
        m_pMainWnd = pMainFrame;

        // Parse command line for standard shell commands, DDE, file open
//        CCommandLineInfo cmdInfo;
        ParseCommandLine(m_cmdInfo);

        // 禁止应用程序启动时自动创建新文档
        if (m_cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
                m_cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

        // Dispatch commands specified on the command line
        if (!ProcessShellCommand(m_cmdInfo))
                return FALSE;

        // 载入DLL,获取函数指针
        hDll = :oadLibrary("CodeTran.dll");
        if (hDll == NULL)  AfxMessageBox("LoadLibrary Error!");
        EtoANP = (lpDLLFun_EtoANP)::GetProcAddress(hDll, "EtoANP");
        if (EtoANP == NULL)  AfxMessageBox("GetProcAddress-EtoANP Error!");
        char src[] = "\xF1\xF2";
        char dst[3];
        EtoANP((unsigned char *)dst, (unsigned char *)src, 2);

        OnFileNew2();        //启动中间业务交易报文接收服务
        OnFileNew1();        //启动卡业务交易报文接收服务
//        pMainFrame->MDITile(MDITILE_VERTICAL); //使多个窗口按照垂直平铺的方式均匀排列在主框架窗口内

        // The main window has been initialized, so show and update it.
        if (!m_cmdInfo.m_bHideWindow)
        {
                pMainFrame->ShowWindow(SW_SHOW);
                pMainFrame->UpdateWindow();
        }

        return TRUE;
}

//***************************************************************************
int CTCPServerApp::ExitInstance()
{
        // TODO: Add your specialized code here and/or call the base class
        if (hDll)                  ::FreeLibrary(hDll);

        return CWinApp::ExitInstance();
}

//***************************************************************************
void CTCPServerApp::OnFileNew()
{
        ASSERT(m_pDocTemplate0 != NULL);
        ASSERT_KINDOF(CDocTemplate, m_pDocTemplate0);

        CSetPortDlg dlg;
        if (dlg.DoModal() == IDOK)
        {
                m_nListenPort = dlg.m_nPort;
                m_bSpecialListen = FALSE;
                m_pDocTemplate0->OpenDocumentFile(NULL);
                m_pMainWnd->SetWindowText(_T("TCP Socket 服务器端侦听接收显示程序"));
        }
}

//***************************************************************************
void CTCPServerApp::OnFileNew1()
{
        ASSERT(m_pDocTemplate1 != NULL);
        ASSERT_KINDOF(CDocTemplate, m_pDocTemplate1);

        m_nListenPort = 6003;        //卡业务**端口:6003
        m_bSpecialListen = TRUE;
        m_pDocTemplate1->OpenDocumentFile(NULL);
}

//***************************************************************************
void CTCPServerApp::OnFileNew2()
{
        ASSERT(m_pDocTemplate2 != NULL);
        ASSERT_KINDOF(CDocTemplate, m_pDocTemplate2);

        m_nListenPort = 4553;        //卡业务**端口:4553
        m_bSpecialListen = TRUE;
        m_pDocTemplate2->OpenDocumentFile(NULL);
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
        CAboutDlg();

// Dialog Data
        //{{AFX_DATA(CAboutDlg)
        enum { IDD = IDD_ABOUTBOX };
        //}}AFX_DATA

        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CAboutDlg)
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
        //}}AFX_VIRTUAL

// Implementation
protected:
        //{{AFX_MSG(CAboutDlg)
                // No message handlers
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
        //{{AFX_DATA_INIT(CAboutDlg)
        //}}AFX_DATA_INIT
}

void CAboutDlg:oDataExchange(CDataExchange* pDX)
{
        CDialog:oDataExchange(pDX);
        //{{AFX_DATA_MAP(CAboutDlg)
        //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
        //{{AFX_MSG_MAP(CAboutDlg)
                // No message handlers
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CTCPServerApp::OnAppAbout()
{
        CAboutDlg aboutDlg;
        aboutDlg.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CMyCommandLineInfo
CMyCommandLineInfo::CMyCommandLineInfo()
{
        m_bHideWindow = FALSE;
        m_bDispRecv = FALSE;
        m_bDispSuccess = FALSE;
}

CMyCommandLineInfo::~CMyCommandLineInfo()
{
}

//***************************************************************************
//重载CCommandLineInfo类的ParseParam函数
void CMyCommandLineInfo:arseParam(LPCTSTR lpszParam, BOOL bFlag, BOOL bLast)
{
        CString        strArg(lpszParam);
        if (bFlag)
        {
                if (!strArg.CompareNoCase("HW"))  m_bHideWindow = TRUE;
                else if (!strArg.CompareNoCase("DP"))  m_bDispRecv = TRUE;
                else if (!strArg.CompareNoCase("DS"))  m_bDispSuccess = TRUE;
        }

        CCommandLineInfo:arseParam(lpszParam, bFlag, bLast);
}


/////////////////////////////////////////////////////////////////////////////
// CTCPServerApp message handlers
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2014-4-10 11:48:18 | 只看该作者
好东西 谢谢分享
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-21 13:51 , Processed in 0.074049 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表