vs2010编写C++程序,静态库使用DLL,生成的程序1.6兆,怎么会这么大,有没有人知道可以怎么解决把程序弄小点,并且能在没有安装VS2010MFC库的机子上运行:
代码
#include "stdafx.h"
#include "ra2.h"
#include "ra2Dlg.h"
#include "afxdialogex.h"
#include <Tlhelp32.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Cra2Dlg 对话框
Cra2Dlg::Cra2Dlg(CWnd* pParent /*=NULL*/)
: CDialogEx(Cra2Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void Cra2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(Cra2Dlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_READ, &Cra2Dlg::OnBnClickedRead)
ON_BN_CLICKED(IDC_WRITE, &Cra2Dlg::OnBnClickedWrite)
ON_WM_HOTKEY()
END_MESSAGE_MAP()
// Cra2Dlg 消息处理程序
BOOL Cra2Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
SetBackgroundColor(RGB(200,240,240),1);
AdjustPrivileges();
::RegisterHotKey(m_hWnd,1,MOD_ALT,'Q');
::RegisterHotKey(m_hWnd,2,MOD_CONTROL,'W');
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void Cra2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR Cra2Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void Cra2Dlg::OnBnClickedRead()
{
DWORD addr,baseaddr,pid,taddr;
int a;
HANDLE hproce;
CString cs;
baseaddr=0x0a1e0c4;
pid=GetProcessIdFromName(_T("Game.exe"));
if(!pid)
MessageBox(_T("游戏尚未运行"),_T("提示"),0);
else
{
hproce=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
ReadProcessMemory(hproce,(LPCVOID)baseaddr,(LPVOID)&taddr,4,NULL);
addr=taddr+0x24c;
ReadProcessMemory(hproce,(LPCVOID)addr,(LPVOID)&a,4,NULL);
cs.Format(_T("%d"),a);
SetDlgItemTextW(IDC_EDIT1,cs);
CloseHandle(hproce);
}
}
void Cra2Dlg::OnBnClickedWrite()
{
// TODO: 在此添加控件通知处理程序代码
DWORD addr,baseaddr,pid,taddr;
int a;
HANDLE hproce;
baseaddr=0x0a1e0c4;
pid=GetProcessIdFromName(_T("Game.exe"));
if(!pid)
MessageBox(_T("游戏尚未运行"),_T("提示"),0);
else
{
hproce=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
ReadProcessMemory(hproce,(LPCVOID)baseaddr,(LPVOID)&taddr,4,NULL);
addr=taddr+0x24c;
a=GetDlgItemInt(IDC_EDIT1,0,1);
WriteProcessMemory(hproce,(LPVOID)addr,(LPCVOID)&a,4,NULL);
CloseHandle(hproce);
}
}
DWORD Cra2Dlg::GetProcessIdFromName(LPCTSTR name)
{
PROCESSENTRY32 pe;
DWORD id=0;
HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe.dwSize=sizeof(pe);
if(!Process32First(hSnapshot,&pe))
return 0;
do
{
pe.dwSize=sizeof(pe);
if(Process32Next(hSnapshot,&pe)==FALSE )
break;
if(_tcscmp(pe.szExeFile,name)==0)
{
id=pe.th32ProcessID;
break;
}
}
while(1);
CloseHandle(hSnapshot);
return id;
}
bool Cra2Dlg::AdjustPrivileges() {
HANDLE hToken;
TOKEN_PRIVILEGES tp;
TOKEN_PRIVILEGES oldtp;
DWORD dwSize=sizeof(TOKEN_PRIVILEGES);
LUID luid;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED) return true;
else return false;
}
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) {
CloseHandle(hToken);
return false;
}
ZeroMemory(&tp, sizeof(tp));
tp.PrivilegeCount=1;
tp.Privileges[0].Luid=luid;
tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
/* Adjust Token Privileges */
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), &oldtp, &dwSize)) {
CloseHandle(hToken);
return false;
}
// close handles
CloseHandle(hToken);
return true;
}
void Cra2Dlg::OnHotKey(UINT nHotKeyId, UINT nKey1, UINT nKey2)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
switch(nHotKeyId)
{
case 1:
{
DWORD addr,baseaddr,pid,taddr;
int a;
HANDLE hproce;
baseaddr=0x0a1e0c4;
pid=GetProcessIdFromName(_T("Game.exe"));
if(!pid)
MessageBox(_T("游戏尚未运行"),_T("提示"),0);
else
{
hproce=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
ReadProcessMemory(hproce,(LPCVOID)baseaddr,(LPVOID)&taddr,4,NULL);
addr=taddr+0x24c;
a=GetDlgItemInt(IDC_EDIT1,0,1);
if(a>10000&&a<9999999)
WriteProcessMemory(hproce,(LPVOID)addr,(LPCVOID)&a,4,NULL);
else
{
a=1000000;
WriteProcessMemory(hproce,(LPVOID)addr,(LPCVOID)&a,4,NULL);
}
CloseHandle(hproce);
}
}
break;
case 2:
MessageBox(_T("11111111111111"),_T("提示"),0);
break;
}
CDialogEx::OnHotKey(nHotKeyId, nKey1, nKey2);
}
BOOL Cra2Dlg::DestroyWindow()
{
// TODO: 在此添加专用代码和/或调用基类
::UnregisterHotKey(m_hWnd,1);
::UnregisterHotKey(m_hWnd,2);
return CDialogEx::DestroyWindow();
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!