how can i convert a string result to LPVOID?

imagine that my string value is a variable adress. can i convert that value to LPVOID?(i mean the value and not the string adress)
No. Let's assume an LPVOID is 32 bits. If your string is more than 4 bytes, how are you going to store that in 32 bits?

but imagine the string value it's: 0x28fac4
how can i add it to LPVOID? i understand that i realy need convert it.
If you're storing a pointer value as a string, you're probably doing something very questionable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>

int main()
{
    int i = 5;

    std::cout << &i << '\n';

    void* ptr = &i;
    intptr_t as_int = reinterpret_cast<std::intptr_t>(ptr);

    std::ostringstream oss;
    oss << std::hex << std::showbase << as_int;
    std::cout << oss.str() << '\n';

    as_int = 0;
    ptr = nullptr;

    as_int = std::stoll(oss.str(), nullptr, 16);

    ptr = reinterpret_cast<void*>(as_int);

    std::cout << ptr << '\n';
}
I missed that your string value was a variable address.

Any technique for converting a hex value to an unsigned long (assuming LPVOID and unsigned long are the same size) will work.
Topic archived. No new replies allowed.