D
D
dominy2021-08-17 18:26:30
C++ / C#
dominy, 2021-08-17 18:26:30

How to pass a pointer to a function if it takes a reference?

hello i have a function

template <typename type>
  static void readMemory(uintptr_t offset, unsigned int length, type var) {
    ReadProcessMemory(targetHandle, (LPVOID)offset, &var, length * sizeof(type), 0);
  }

I call her

uintptr_t adr; readMemory<uintptr_t&>(0x183422, 1, adr);


But now I need to pass a pointer to ReadProcessMemory

wchar_t* str = new wchar_t[length]; readMemory<wchar_t*>(0x124322, length, str);

//This doesn't work because ReadProcessMemory gets a reference from a pointer, how can I fix the situation...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-08-17
@dominy

No way. Make your function accept a pointer:

template <typename type>
  static void readMemory(uintptr_t offset, unsigned int length, type* var) {
    ReadProcessMemory(targetHandle, (LPVOID)offset, var, length * sizeof(type), 0);
  }

uint8_t arr[100500];
readMemory<uint8_t>(0x00, 10, arr);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question