string to LPVOID

Hello,
I have problem converting string to lpvoid.
It does convert but if input is "0x00309E40" output 0x13db92cc
1
2
3
4
5

 std::string adresss = "0x";
 std::string ii = ui->lineEdit->text().toStdString();
                  adresss += ii;
  LPVOID adr = (LPVOID)adresss.c_str();

I am using Qt 5.
There is no input or output here.

You should not store the address returned by string::c_str. (And that address should certainly not be equal to whatever text is contained in the string address.)
It seems what OP wants is more like
1
2
3
4
5
6
7
intptr_t int_address;
{
    std::stringstream stream;
    stream <<std::hex<<ui->lineEdit->text().toStdString();
    stream >>int_address;
}
void *address = (void *)int_address;
Sorry for wrong termins.
By input i mean if string to convert is "0x00309E40" then converted lpvoid is 0x13db92cc.
How could i convert input from ui->lineEdit->text() to proper format for adress lpvoid?

ReadProcessMemory(hProc, (LPVOID)THIS, (LPVOID) &cbuffer, length1, 0); }

I tryed above code and compiler returned:
error: aggregate 'std::stringstream stream' has incomplete type and cannot be defined
std::stringstream stream;
^

If i put
std::string ii = "0x00309E40";
(LPVOID)&ii
Then code compiles but wont work, if i enter lpvoid manually it works.
Last edited on
To use the code that helios posted you have to include <sstream>
Thanks alot, now i am able to enter adress and pointer.

Now i have problem converting qstring to LPCWSTR.

1
2
 wchar_t win = ui->lineEdit->text()::toWCharArray(); //how to convert it properly?
HWND hWnd = FindWindow (0,  win);

1
2
 HWND hWnd = FindWindow (0, ui->lineEdit->text()::toWCharArray());
   


compiler says
error: cannot convert 'QString' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HWND__* FindWindowW(LPCWSTR, LPCWSTR)'
HWND hWnd = FindWindow (0, ui->lineEdit->text()::toWCharArray());
^

it works this way
HWND hWnd = FindWindow (0, L"app";
Last edited on
Topic archived. No new replies allowed.