I have defined several macros, but one cannot be recognized. May I ask where the problem lies
Here are the codes for two files
I am a newcomer to C++, and I copied the macros from elsewhere
Writing someone else’s source code like this did not result in any errors, I copied it completely from their project
d2ptrs.h:
<code> #pragma once
#include "D2struct.h"
#include "MemHelper.h"
#ifdef _DEFINE_PTRS
#define FUNCPTR(dll, name, callingret, args, ...)
static Offsets f##dll##_##name##_offsets = { __VA_ARGS__ };
__declspec(naked) callingret dll##_##name##args
{
static DWORD f##dll##_##name = NULL;
if(f##dll##_##name == NULL)
{
__asm { pushad }
f##dll##_##name = MemHelper::GetDllOffset(dll, *(&f##dll##_##name##_offsets._111b));
__asm { popad }
}
__asm jmp [f##dll##_##name]
}
#define VARPTR(dll, name, type, ...)
type** Var_##dll##_##name##(VOID)
{
static DWORD f##Var_##dll##_##name = NULL;
if(f##Var_##dll##_##name## == NULL)
{
static Offsets f##Var_##_##name##_offsets = { __VA_ARGS__ };
static int address = *(&f##Var_##_##name##_offsets._111b);
f##Var_##dll##_##name## = MemHelper::GetDllOffset(dll, address);
}
return (type**)&##f##Var_##dll##_##name;
}
#else
...
#endif
FUNCPTR(D2CLIENT, PrintGameString, void __stdcall, (wchar_t* wMessage, int nColor), 0x16780)
FUNCPTR(D2CLIENT, GetPlayerXOffest, int __stdcall, (), 0x1BBE0)
FUNCPTR(D2CLIENT, GetPlayerYOffset, int __stdcall, (), 0x1BBF0)
VARPTR(D2CLIENT, MouseX, DWORD, 0x11B828)
VARPTR(D2CLIENT, MouseY, DWORD, 0x11B824)
#undef FUNCPTR
#undef ASMPTR
#undef VARPTR
</code>
<code> #pragma once
#include "D2struct.h"
#include "MemHelper.h"
#ifdef _DEFINE_PTRS
#define FUNCPTR(dll, name, callingret, args, ...)
static Offsets f##dll##_##name##_offsets = { __VA_ARGS__ };
__declspec(naked) callingret dll##_##name##args
{
static DWORD f##dll##_##name = NULL;
if(f##dll##_##name == NULL)
{
__asm { pushad }
f##dll##_##name = MemHelper::GetDllOffset(dll, *(&f##dll##_##name##_offsets._111b));
__asm { popad }
}
__asm jmp [f##dll##_##name]
}
#define VARPTR(dll, name, type, ...)
type** Var_##dll##_##name##(VOID)
{
static DWORD f##Var_##dll##_##name = NULL;
if(f##Var_##dll##_##name## == NULL)
{
static Offsets f##Var_##_##name##_offsets = { __VA_ARGS__ };
static int address = *(&f##Var_##_##name##_offsets._111b);
f##Var_##dll##_##name## = MemHelper::GetDllOffset(dll, address);
}
return (type**)&##f##Var_##dll##_##name;
}
#else
...
#endif
FUNCPTR(D2CLIENT, PrintGameString, void __stdcall, (wchar_t* wMessage, int nColor), 0x16780)
FUNCPTR(D2CLIENT, GetPlayerXOffest, int __stdcall, (), 0x1BBE0)
FUNCPTR(D2CLIENT, GetPlayerYOffset, int __stdcall, (), 0x1BBF0)
VARPTR(D2CLIENT, MouseX, DWORD, 0x11B828)
VARPTR(D2CLIENT, MouseY, DWORD, 0x11B824)
#undef FUNCPTR
#undef ASMPTR
#undef VARPTR
</code>
#pragma once
#include "D2struct.h"
#include "MemHelper.h"
#ifdef _DEFINE_PTRS
#define FUNCPTR(dll, name, callingret, args, ...)
static Offsets f##dll##_##name##_offsets = { __VA_ARGS__ };
__declspec(naked) callingret dll##_##name##args
{
static DWORD f##dll##_##name = NULL;
if(f##dll##_##name == NULL)
{
__asm { pushad }
f##dll##_##name = MemHelper::GetDllOffset(dll, *(&f##dll##_##name##_offsets._111b));
__asm { popad }
}
__asm jmp [f##dll##_##name]
}
#define VARPTR(dll, name, type, ...)
type** Var_##dll##_##name##(VOID)
{
static DWORD f##Var_##dll##_##name = NULL;
if(f##Var_##dll##_##name## == NULL)
{
static Offsets f##Var_##_##name##_offsets = { __VA_ARGS__ };
static int address = *(&f##Var_##_##name##_offsets._111b);
f##Var_##dll##_##name## = MemHelper::GetDllOffset(dll, address);
}
return (type**)&##f##Var_##dll##_##name;
}
#else
...
#endif
FUNCPTR(D2CLIENT, PrintGameString, void __stdcall, (wchar_t* wMessage, int nColor), 0x16780)
FUNCPTR(D2CLIENT, GetPlayerXOffest, int __stdcall, (), 0x1BBE0)
FUNCPTR(D2CLIENT, GetPlayerYOffset, int __stdcall, (), 0x1BBF0)
VARPTR(D2CLIENT, MouseX, DWORD, 0x11B828)
VARPTR(D2CLIENT, MouseY, DWORD, 0x11B824)
#undef FUNCPTR
#undef ASMPTR
#undef VARPTR
dllmain.cpp:
<code> #define _DEFINE_PTRS
#include <sstream>
#include <thread>
#include "d2ptrs.h"
void OutputDebugMsg() {
int xpos = D2CLIENT_GetPlayerXOffest();
int ypos = D2CLIENT_GetPlayerYOffset();
wchar_t message[256];
std::wstringstream wss;
wss << L",x:"<<xpos<<L"y:"<<ypos;
std::wstring msg = wss.str();
wcscpy_s(message, msg.c_str());
D2CLIENT_PrintGameString(message, 0);
int mX = (*p_D2CLIENT_MouseX); //problem:Undefined identifier 'p_D2CLIENT_MouseX'
}
void StartUp() {
OutputDebugStringA("start");
std::thread t(OutputDebugMsg);
t.detach();
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
StartUp();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
</code>
<code> #define _DEFINE_PTRS
#include <sstream>
#include <thread>
#include "d2ptrs.h"
void OutputDebugMsg() {
int xpos = D2CLIENT_GetPlayerXOffest();
int ypos = D2CLIENT_GetPlayerYOffset();
wchar_t message[256];
std::wstringstream wss;
wss << L",x:"<<xpos<<L"y:"<<ypos;
std::wstring msg = wss.str();
wcscpy_s(message, msg.c_str());
D2CLIENT_PrintGameString(message, 0);
int mX = (*p_D2CLIENT_MouseX); //problem:Undefined identifier 'p_D2CLIENT_MouseX'
}
void StartUp() {
OutputDebugStringA("start");
std::thread t(OutputDebugMsg);
t.detach();
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
StartUp();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
</code>
#define _DEFINE_PTRS
#include <sstream>
#include <thread>
#include "d2ptrs.h"
void OutputDebugMsg() {
int xpos = D2CLIENT_GetPlayerXOffest();
int ypos = D2CLIENT_GetPlayerYOffset();
wchar_t message[256];
std::wstringstream wss;
wss << L",x:"<<xpos<<L"y:"<<ypos;
std::wstring msg = wss.str();
wcscpy_s(message, msg.c_str());
D2CLIENT_PrintGameString(message, 0);
int mX = (*p_D2CLIENT_MouseX); //problem:Undefined identifier 'p_D2CLIENT_MouseX'
}
void StartUp() {
OutputDebugStringA("start");
std::thread t(OutputDebugMsg);
t.detach();
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
StartUp();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
19