51Testing软件测试论坛

标题: 性能测试工具源代码 as400 [打印本页]

作者: qsword    时间: 2014-4-7 11:15
标题: 性能测试工具源代码 as400
完整代码在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
作者: jiutianwow    时间: 2014-4-10 11:48
好东西 谢谢分享




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2