我在Struct.h中定义了很多结构,这里只列举出错的结构THREADLIST ;MODREF; PDB95 ;PDB98;定义格式如下:(1):THREADLIST
typedef struct {
struct THREADLIST *pNext;
struct THREADLIST *pPrev;
DWORD pTDB;
} THREADLIST, *PTHREADLIST;
(2):MODREF
typedef struct _MODREF {
struct MODREF* pNextModRef;
DWORD un1;
……(太长了就省略不写了)
} MODREF, *PMODREF;
(3):typedef struct _PDB95 {
DWORD Type;
DWORD cReference;
……(略)
} PDB95, *PPDB95;
(4):typedef struct _PDB98 {
BYTE Type;
BYTE Unknown_A;
……(略)
} PDB98, *PPDB98;当然里面还有其他的结构体,由于没有出现问题就不说了,我自我觉得定义在格式上是没有错的,而且也检查过自己没有重复定义。
下面是另外一个模块InjectModule
(InjectModule.h)中头文件:#include <windows.h>和#include <TLHELP32.H>
下面在InjectModule.cpp中头文件的不同会出现两种错误
(一)第一种格式:
#include "stdafx.h"
#include <stdlib.h>
#include <stddef.h>
#include "InjectModule.h"
#include "Struct.h"
编译出错情况如下:Compiling...
InjectModule.cpp
d:\myproject\dllin\struct.h(511) : error C2371: 'THREADLIST' : redefinition; different basic types
d:\myproject\dllin\struct.h(508) : see declaration of 'THREADLIST'
d:\myproject\dllin\struct.h(557) : error C2371: 'MODREF' : redefinition; different basic types
d:\myproject\dllin\struct.h(546) : see declaration of 'MODREF'
d:\myproject\dllin\struct.h(648) : error C2371: 'PDB95' : redefinition; different basic types
d:\myproject\dllin\struct.h(623) : see declaration of 'PDB95'
d:\myproject\dllin\struct.h(877) : error C2371: 'PDB98' : redefinition; different basic types
d:\myproject\dllin\struct.h(851) : see declaration of 'PDB98'
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2065: 'K32OBJ_PROCESS' : undeclared identifier
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2227: left of '->Type' must point to class/struct/union
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2065: 'K32OBJ_THREAD' : undeclared identifier
执行 cl.exe 时出错.(二)第二种格式
#include "Struct.h"
#include "stdafx.h"
#include <stdlib.h>
#include <stddef.h>
#include "InjectModule.h"编译出错如下:Compiling...
InjectModule.cpp
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2065: 'PTDB95' : undeclared identifier
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2146: syntax error : missing ')' before identifier 'pTDB'
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2059: syntax error : ')'
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2227: left of '->Type' must point to class/struct/union
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2065: 'K32OBJ_THREAD' : undeclared identifier
执行 cl.exe 时出错.
我自我分析觉得第一种情况可能是在windows本身的某个文件就有那几个结构体的定义,所以我再一次定义就出现了重复。但是如果说windows本身就有那个结构,(这里就以PDB95为例),那为什么我第二种情况会出现'PTDB95' : undeclared identifier呢?
题外话:我在网上下的一个工程,里面也包括Struct.h(内容肯定是跟我的相同的,因为我是粘贴人家的),我编译过这个工程,并不会出现任何的错误。 希望高手能帮我解决一下,我自己都觉得这也许只是一个菜鸟问题吧呵呵。
typedef struct {
struct THREADLIST *pNext;
struct THREADLIST *pPrev;
DWORD pTDB;
} THREADLIST, *PTHREADLIST;
(2):MODREF
typedef struct _MODREF {
struct MODREF* pNextModRef;
DWORD un1;
……(太长了就省略不写了)
} MODREF, *PMODREF;
(3):typedef struct _PDB95 {
DWORD Type;
DWORD cReference;
……(略)
} PDB95, *PPDB95;
(4):typedef struct _PDB98 {
BYTE Type;
BYTE Unknown_A;
……(略)
} PDB98, *PPDB98;当然里面还有其他的结构体,由于没有出现问题就不说了,我自我觉得定义在格式上是没有错的,而且也检查过自己没有重复定义。
下面是另外一个模块InjectModule
(InjectModule.h)中头文件:#include <windows.h>和#include <TLHELP32.H>
下面在InjectModule.cpp中头文件的不同会出现两种错误
(一)第一种格式:
#include "stdafx.h"
#include <stdlib.h>
#include <stddef.h>
#include "InjectModule.h"
#include "Struct.h"
编译出错情况如下:Compiling...
InjectModule.cpp
d:\myproject\dllin\struct.h(511) : error C2371: 'THREADLIST' : redefinition; different basic types
d:\myproject\dllin\struct.h(508) : see declaration of 'THREADLIST'
d:\myproject\dllin\struct.h(557) : error C2371: 'MODREF' : redefinition; different basic types
d:\myproject\dllin\struct.h(546) : see declaration of 'MODREF'
d:\myproject\dllin\struct.h(648) : error C2371: 'PDB95' : redefinition; different basic types
d:\myproject\dllin\struct.h(623) : see declaration of 'PDB95'
d:\myproject\dllin\struct.h(877) : error C2371: 'PDB98' : redefinition; different basic types
d:\myproject\dllin\struct.h(851) : see declaration of 'PDB98'
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2065: 'K32OBJ_PROCESS' : undeclared identifier
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2227: left of '->Type' must point to class/struct/union
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2065: 'K32OBJ_THREAD' : undeclared identifier
执行 cl.exe 时出错.(二)第二种格式
#include "Struct.h"
#include "stdafx.h"
#include <stdlib.h>
#include <stddef.h>
#include "InjectModule.h"编译出错如下:Compiling...
InjectModule.cpp
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2065: 'PTDB95' : undeclared identifier
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2146: syntax error : missing ')' before identifier 'pTDB'
D:\MyProject\DLLIN\InjectModule.cpp(449) : error C2059: syntax error : ')'
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2227: left of '->Type' must point to class/struct/union
D:\MyProject\DLLIN\InjectModule.cpp(451) : error C2065: 'K32OBJ_THREAD' : undeclared identifier
执行 cl.exe 时出错.
我自我分析觉得第一种情况可能是在windows本身的某个文件就有那几个结构体的定义,所以我再一次定义就出现了重复。但是如果说windows本身就有那个结构,(这里就以PDB95为例),那为什么我第二种情况会出现'PTDB95' : undeclared identifier呢?
题外话:我在网上下的一个工程,里面也包括Struct.h(内容肯定是跟我的相同的,因为我是粘贴人家的),我编译过这个工程,并不会出现任何的错误。 希望高手能帮我解决一下,我自己都觉得这也许只是一个菜鸟问题吧呵呵。
在头文件中加上
#pragma once
再看看啥编译错误
typedef struct THREADLIST{
struct THREADLIST *pNext;
struct THREADLIST *pPrev;
DWORD pTDB;
} *PTHREADLIST;typedef struct MODREF {
struct MODREF* pNextModRef;
DWORD un1;
}*PMODREF;......