// IPCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "IPC.h"
#include "IPCDlg.h"
#include "ksreglib.h"

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

/////////////////////////////////////////////////////////////////////////////
// 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)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

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

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(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()

/////////////////////////////////////////////////////////////////////////////
// CIPCDlg dialog

CIPCDlg::CIPCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CIPCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CIPCDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CIPCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIPCDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CIPCDlg, CDialog)
	//{{AFX_MSG_MAP(CIPCDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_btn7, Onbtn7)
	ON_BN_CLICKED(IDC_btn6, Onbtn6)
	ON_BN_CLICKED(IDC_btn5, Onbtn5)
	ON_BN_CLICKED(IDC_btn4, Onbtn4)
	ON_BN_CLICKED(IDC_btn3, Onbtn3)
	ON_BN_CLICKED(IDC_btn2, Onbtn2)
	ON_BN_CLICKED(IDC_btn1, Onbtn1)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIPCDlg message handlers

BOOL CIPCDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	// TODO: Add extra initialization here

	ksLoadDLLs(); //★★★★★★★★★★★★加载DLL


    _int32 sockPort = 12345;                 // sock服务端口号
    
    // ★★★★★★ 该数据从管理端获取后设置到这里：【软件列表】->右上角【新签名数据】按钮单击即可获取。
	signData = __TEXT("");
	signData += __TEXT("b7e231942dc15290dc9040c3db205210e95cfcc10cf8459ddff4583c3c42800436d0135bc12b0960c2d4bdd72795952f2278");
	signData += __TEXT("99fa2fd109210302aad4bc22b264f995ece9deeb184077ef9b1fe3b5aa75eec8d4de2b3b3d07a7266e5a7a6498740b601d27");
	signData += __TEXT("ab988cdeba81eca2aa39da028416d0ffc489dfd91e0f2185986d8601542cb9af8b4df6b526a75586909c5f109b1e04426389");
	signData += __TEXT("1da1275644d7d18ece5badb60b19afe2d53e8b20e64b30ee128add4386559f1e77f7c80ae8b7b56a3e472b92f9824078fbf8");
	signData += __TEXT("2ecaf66ac01384fb1cd261cb88270aa0464313858d0355919759557e1136c8ffec8d6a7a4835f9b7c00f4ec58f85f7b4be5b");
	signData += __TEXT("22bd54d07da0f9ec596dbf95ecf1b4f4456d14f9f98fdb81aea62024108e492bdc2a41429ed078d1add7467848a7b4fcb3d8");
	signData += __TEXT("d0dee4f8f3bab8d3dda0f1bc14e8d1615f81665b73688d651acf6f9b7d8e8d3c09c9075aab2b16f774a7f8ba959bfd8751c0");
	signData += __TEXT("50741aa4051ab0dd38eaedf43aa418584400c8eb1f9c26ce9217a29c6e98deddca5de6a17fb5ce70b3f31aa657d13d6cf3d9");

    if(IPC_Connect(sockPort) == 0)
	{
        MsgBox(__TEXT("连接登陆器失败!"));
		::PostQuitMessage(0);
	}
	//-- Delphi源代码到这里结束
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CIPCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CIPCDlg::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 CIPCDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CIPCDlg::Onbtn7() 
{
	// TODO: Add your control notification handler code here
    _int32 tresult;
    CString errinfo = __TEXT("");
    tresult = kpoints(3, &errinfo);  // 记录错误变量是传址的，扣点出错时该变量值会记录错误信息
    if(tresult == -1)   // 扣点失败
    {
        MsgBox(errinfo);
        //扣点失败，你可以根据据错误提示，来进行相应的处理，我这里只是关闭程序
        myExitProcess();
    }
	//
	CString lsMSG;
	lsMSG.Format(__TEXT("扣点成功，用户剩余点数%d"), tresult);
    MsgBox(lsMSG);  //显示测试结果
}

void CIPCDlg::Onbtn6() 
{
	// TODO: Add your control notification handler code here
    CString tresult(__TEXT("IPC_GetData所有序数据\n\r"));
	CString msg[20];
	msg[0] = __TEXT("【验证次数】：");
	msg[1] = __TEXT("【返回信息A】：");
	msg[2] = __TEXT("【返回信息B】：");
	msg[3] = __TEXT("【用户附属性】：");
	msg[4] = __TEXT("【绑定信息】：");
	msg[5] = __TEXT("【剩余时间】：");
	msg[6] = __TEXT("【软件下载地址】：");
	msg[7] = __TEXT("【用户通道数】：");
	msg[8] = __TEXT("【服务端软件版本】：");
	msg[9] = __TEXT("【更新日志URL】：");
	msg[10] = __TEXT("【用户天数】：");
	msg[11] = __TEXT("【服务端时间戮】：");
	msg[12] = __TEXT("【用户剩余点数】：");
	msg[13] = __TEXT("【用户标签】：");
	msg[14] = __TEXT("【用户充值次数】：");
	msg[15] = __TEXT("【返回的域名】：");
	msg[16] = __TEXT("【是否可单机多开】：");
	msg[17] = __TEXT("【用户名】：");
	msg[18] = __TEXT("【是否公用帐号】：");
	msg[19] = __TEXT("【是否检查登陆标识】：");
	//
	CString s(__TEXT(""));
	for(int i = 0; i <= 19; ++i)
	{
		s.Format(__TEXT("IPC_GetData(%d)%s%s\n\r"), i, msg[i], IPC_GetData(i));
		tresult += s;
	}
    MsgBox(tresult);  //显示测试结果
}

void CIPCDlg::Onbtn5() 
{
	// TODO: Add your control notification handler code here
      chkPass(1);
      MsgBox(__TEXT("验证通过"));
}

void CIPCDlg::Onbtn4() 
{
	// TODO: Add your control notification handler code here
      chkPass(0);
      MsgBox(__TEXT("验证通过"));
	
}

void CIPCDlg::Onbtn3() 
{
	// TODO: Add your control notification handler code here
    IPC_advapifree(__TEXT("v_getb,100,200"));
    MsgBox(advapi(__TEXT("v_getb,100,200"))); //显示测试结果 这里用的示例接口 v_getb 弹出返回值
	
}

void CIPCDlg::Onbtn2() //advapi测试2 
{
	// TODO: Add your control notification handler code here
    MsgBox(advapi(__TEXT("v_getb,100,200"))); //显示测试结果 这里用的示例接口 v_getb 弹出返回值
	
}

void CIPCDlg::Onbtn1() //advapi测试1 
{
	// TODO: Add your control notification handler code here
    MsgBox(advapi(__TEXT("v_geta")));  //显示测试结果 这里用的示例接口 v_geta 弹出返回值
}

void CIPCDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default

	ksFreeDLLs();//★★★★★★★★★★★★卸载DLL

	CDialog::OnClose();
}
