-
-
[分享]分享一个读取无限多级指针的函数(需要C++11支持)
-
发表于:
2017-5-25 16:32
6460
-
[分享]分享一个读取无限多级指针的函数(需要C++11支持)
#define E_BAD_PTR 0xFFFFFFFF
template<typename T, typename ... ARGS>
T Read(ARGS...args)
{
DWORD parm[] = { (DWORD)args... };
DWORD RetVal = 0;
__try
{
for (DWORD curaddr : parm)
{
RetVal += curaddr;
RetVal = *(DWORD*)RetVal;
}
}
__except (1)
{
return (T)E_BAD_PTR;
}
return (T)RetVal;
}
调用:
DWORD dwVal = Read<DWORD>(0x12345678,0x123,0x12,1);
WORD wVal = Read<WORD>(0x12345678,0x123,0x12,1);
BYTE bVal = Read<BYTE>(0x12345678,0x123,0x12,1);
vs2015下编译正常,其他的版本不清楚!
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!