转自 Rover12421 ‘s Blog

二.编译Gh0st

成功编译CJ60Lib界面库之后,就可以开始编译Gh0st了。

2.1 转换Gh0st3.6项目

直接用VS2010打开Gh0st3.6\gh0st.dsw 提示转换项目,确定转换就行了。这里一共三个项目:gh0st,install,svchost。编译的时候需要先编译svchost再编译install,最后才编译gh0st。

 

2.2 编译svchost

相同的错误修改就不再说了,参看前面的修改方法。 
修改已说过的错误,再继续下面的错误修改。

2.2.1

1>common\FileManager.cpp(202): error C2440: “初始化”: 无法从“const char *”转换为“char *” 
1>          转换丢失限定符

char *lpExt = strrchr(lpFile‘.’); 
修改为: 
const char *lpExt = strrchr(lpFile‘.’);

 

1>e:\programming\vs2010\gh0st3.6\server\svchost\common\loop.h(160): error C2440: “=”: 无法从“const char *”转换为“char *” 
1>          转换丢失限定符

char *lpFileName = NULL;

lpFileName = strrchr(lpURL‘/’) + 1;

修改为:

const char *lpFileName = NULL;

lpFileName = strrchr(lpURL‘/’) + 1;

2.2.2

1>common\ScreenSpy.cpp(355): error C2062: 意外的类型“int”

for (int i = 0, int nToJump = 0; i < nHeighti += nToJump
修改为: 
for (int i = 0, nToJump = 0; i < nHeighti += nToJump)

2.2.3

1>common\VideoManager.cpp(123): error C4430: 缺少类型说明符 – 假定为 int。注意: C++ 不支持默认 int

定位在: 
static dwLastScreen = GetTickCount(); 
这个错误前面已经提到过,是添加现式定义类型int。这里添加现式类型为 DWORD 比较好,因为后面的函数GetTickCount返回值是DWORD类型。在这里修改如下: 
static DWORD dwLastScreen = GetTickCount();

2.2.4

1>common\ScreenManager.cpp(7): fatal error C1083: 无法打开包括文件:“winable.h”: No such file or directory

Winable头文件从VS2008里面就已经不存在了,MSDN里描述如下:

从 Visual Studio 早期版本升级项目时,您可能必须修改 WINVER 和 _WIN32_WINNT 宏,以便它们大于或等于 0×0500。 
已移除 Windows API 头文件 Winable.h。而改为包括 Winuser.h。

因为Winuser默认已经包含进来了,所以直接注释这句话就行了。但是如果直接这样,引用Winable中的函数就会出现未定义错误。所以这里除了需要注释这个头文件包含,还需要注释这个文件中的_WIN32_WINNT宏定义,或者修改宏定义大于等于500。我这里直接注释掉了。

#define _WIN32_WINNT 0×0400 
#include "ScreenManager.h" 
#include "until.h" 
#include <winable.h> // BlockInput

修改为:

//#define _WIN32_WINNT 0×0400 
#include "ScreenManager.h" 
#include "until.h" 
//#include <winable.h> // BlockInput

2.3 编译install

这个能直接编译通过,就算不修改默认字符集,但还是建议和前面一样,修改下默然字符。

2.4 编译gh0st

一开始编译就会有个错误提示而终止,如果不修改没法正常编译。

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\afx.h(24): fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

这个还是需要修改属性页。需要把代码生成里的运行时库改成/MT。如图:

点击查看原图


 

修改之后重新编译就能看到很多错误了。在继续下面的错误修改之前,先把前面讲到的错误类型给修改好。

2.4.1

1>control\BtnST.cpp(4): fatal error C1083: 无法打开包括文件:“stdafx.h”: No such file or directory

提示找不到stdafx.h,其实这个文件是存在的。在属性里添加“./”的包含目录就能解决了。 
在属性页的C/C++—General—Additional Include Directories 里添加。

原来的是: 
CJ60lib/Include;../common;%(AdditionalIncludeDirectories)

修改后为: 
./;CJ60lib/Include;../common;%(AdditionalIncludeDirectories)

如图:

点击查看原图


 

2.4.2

1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(27): error C2011: “BGTYPE”:“enum”类型重定义 
1>          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\vssym32.h(14) : 参见“BGTYPE”的声明
 
1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(33): error C2011: “IMAGELAYOUT”:“enum”类型重定义
 
1>          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\vssym32.h(25) : 参见“IMAGELAYOUT”的声明
 
1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(38): error C2011: “BORDERTYPE”:“enum”类型重定义
 
1>          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\vssym32.h(35) : 参见“BORDERTYPE”的声明
 
1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(44): error C2011: “FILLTYPE”:“enum”类型重定义
 
1>          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\vssym32.h(46) : 参见“FILLTYPE”的声明
 
1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(52): error C2011: “SIZINGTYPE”:“enum”类型重定义
 
1>          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\vssym32.h(59) : 参见“SIZINGTYPE”的声明
 
1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(58): error C2011: “HALIGN”:“enum”类型重定义
 
1>          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\vssym32.h(70) : 参见“HALIGN”的声明
 
1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(64): error C2011: “CONTENTALIGNMENT”:“enum”类型重定义
 
1>          C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\vssym32.h(81) : 参见“CONTENTALIGNMENT”的声明
 
1>e:\programming\vs2010\gh0st3.6\gh0st\TmSchema.h(70): error C2011: “VALIGN”:“enum”类型重定义

又是一堆的类型重定义错误,这次需要现式的指出Windows版本才能解决这个问题。打开stdafx.h,在其中添加 #define _WIN32_WINNT 0×0500 。下面是我的操作,实际放置的位置可以自己调整。

E:\Programming\VS2010\Gh0st3.6\gh0st\StdAfx.h

#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 
#include <afxwin.h>         // MFC core and standard components 
#include
 <afxext.h>         // MFC extensions 
#include <afxcview.h>

修改如下:

#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers 
#define _WIN32_WINNT 0×0500 
#include <afxwin.h>         // MFC core and standard components 
#include
 <afxext.h>         // MFC extensions 
#include <afxcview.h>

这里就说下参数的含义,0×0500是指Windows 2000,这个宏定义说明这个程序只是要在Windows 2000 及以上的操作系统上才能正常运行。0×0501 Windows XP、0×0502 Windows Server 2003、 0×0600 Windows Vista、0×0601 Windows 7。

2.4.3

1>TrueColorToolBar.cpp(42): error C2440: “static_cast”: 无法从“void (__thiscall CTrueColorToolBar::* )(NMTOOLBARA *,LRESULT *)”转换为“void (__thiscall CCmdTarget::* )(NMHDR *,LRESULT *)” 
1>          在匹配目标类型的范围内没有具有该名称的函数

这个和1.1.8是一样的。这里再说下。

定位到:

ON_NOTIFY_REFLECT(TBN_DROPDOWNOnToolbarDropDown)

可以在OnToolbarDropDown上点右键跳转到定义(F12),跳转到申明(Ctrl+Alt+F12)

E:\Programming\VS2010\Gh0st3.6\gh0st\TrueColorToolBar.cpp

void CTrueColorToolBar::OnToolbarDropDown(NMTOOLBARpnmtbLRESULT *plr

for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {

修改如下:

void CTrueColorToolBar::OnToolbarDropDown(NMHDRNMHDRpnmtbLRESULT *plr

NMTOOLBARA *pnmtb = (NMTOOLBARA *)NMHDRpnmtb
for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {

E:\Programming\VS2010\Gh0st3.6\gh0st\TrueColorToolBar.h

afx_msg void OnToolbarDropDown(NMTOOLBARpnmhLRESULTplRes);

修改如下:

afx_msg void OnToolbarDropDown(NMHDRNMHDRpnmtbLRESULTplRes);

2.5

      Gh0st就只有这些错误了。下一节将讲解连接错误。