I’m trying to compile some code, but I’m getting an error:
Error invalid conversion from
DWORDtoconst char *
Here’s the code I’m trying to compile:
hWindow = FindWindow(NULL, "Window");
if (hWindow){
GetWindowThreadProcessId(hWindow, &pid);
}
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if(hProcess != NULL) {
SetWindowText(GetDlgItem(MyWindow, MyStatic), pid);
}
How do I convert a DWORD to a const char *?
In this line
pidis a DWORD (as you used it inGetWindowThreadProcessId(hWindow, &pid)which takes aLPDWORDas the second argument). However,SetWindowTextexpects a C-string as it’s second argument, so instead ofpid, you must pass a value of typechar *orchar [].To display the value of
pid, you can make use ofsprintf:You may have to modify the size of
stra little (10 might be too small, or bigger than necessary – that’s up to you and your situation).