⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bootload.cpp

📁 windows ce 下启动代理程序
💻 CPP
字号:
// BootLoad.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "BootLoad.h"
#include "BootLoadDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBootLoadApp

BEGIN_MESSAGE_MAP(CBootLoadApp, CWinApp)
	//{{AFX_MSG_MAP(CBootLoadApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBootLoadApp construction

CBootLoadApp::CBootLoadApp()
	: CWinApp()
{
	// TODO: add construction code here,
	m_Count=0;
	m_pPingSocket = NULL;
	m_bSockIsOk=FALSE;
	m_SocketAddress=_T("192.168.1.100");
	m_bPass=FALSE;
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CBootLoadApp object

CBootLoadApp theApp;
HANDLE HMutexPass;	//m_strPass互斥体
/////////////////////////////////////////////////////////////////////////////
// CBootLoadApp initialization

BOOL CBootLoadApp::InitInstance()
{
	ReadHostIP();
	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	SockCreate();

	
	HMutexPass = ::CreateMutex(NULL,FALSE,NULL);	//互斥体

	// 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.
	CBootLoadDlg* pDlg = new CBootLoadDlg;
	m_pMainWnd = pDlg;
	pDlg->Create(IDD_BOOTLOAD_DIALOG, NULL);
	//pDlg->ShowWindow(SW_HIDE);
	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return TRUE;
}

void CBootLoadApp::SendPing()
{
	int count=-1;
	m_Count++;
	char chsend[100];
	sprintf(chsend,"%d",m_Count);
	count=m_pPingSocket->SendTo(chsend, 100, m_nHostPort, m_SocketAddress);
}

BOOL CBootLoadApp::SockCreate()
{
		// Create the ping socket if neccessary
	if (m_pPingSocket == NULL)
	{
		if ((m_pPingSocket = new CPingSocket()) == NULL)
			return FALSE;
		
		if (!m_pPingSocket->Create(0, SOCK_DGRAM))
			return FALSE;
	}
		
	m_nHostPort = 1001;
	return TRUE;
}

BOOL CBootLoadApp::GetPingEcho()
{
		// The select time is 0 second
	timeval TimeOut = {0L, 0L};
	SOCKET hSocket = m_pPingSocket->m_hSocket;
	fd_set readfds;
	FD_ZERO(&readfds);
	FD_SET(hSocket, &readfds);

	// Test the socket for read pending
	if (!select(0, &readfds, (fd_set *)0, (fd_set *)0, &TimeOut))
		return FALSE;                  // Time out

	// Test wether it is a pending for read
	if (!FD_ISSET(hSocket, &readfds))
		return FALSE;

	// Read the echo
	char chBuf[100];
	UINT uPort;
	CString rSocketAddress;
	
	m_pPingSocket->ReceiveFrom(chBuf, 100, rSocketAddress, uPort, 0);

	return TRUE;
}

void CBootLoadApp::RunSome()
{
	PROCESS_INFORMATION ProcessInfo;
	int aaa=0;
	aaa=CreateProcess(
		_T("\\hard disk\\carryboy\\temp.exe"),
		NULL,	
		NULL,
		NULL,
		NULL,
		0,
		NULL,
		NULL,
		NULL,
		&ProcessInfo); 
	
}

void CBootLoadApp::ReadHostIP()
{
	FILE* StreamIn = fopen("\\hard disk\\carryboy\\HostIP.dat", "r");
	if (StreamIn == NULL)
	{
		AfxMessageBox(_T("不能打开文件:HostIP.dat!\n请退出程序,确认文件的存在."));
		return;
	}
	char strtext[40];
	fscanf(StreamIn, "%s", strtext);	
	m_SocketAddress=strtext;
}

int CBootLoadApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	::CloseHandle(HMutexPass);
	return CWinApp::ExitInstance();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -