Is there a direct way to get window text to a string variable using GetWindowText() without making any char array?
Is there a direct way to get window text to a string variable using GetWindowText() without making any char array?
"The Internet treats censorship as damage and routes around it." - John Gilmore
Direct - no. Without char array - use(C++) a std::vector, eg:Code:int len=GetWindowTextLength(hwnd); std::vector<TCHAR> tmp(len+1,_T('\0')); GetWindowText(hwnd,&tmp[0],len);
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
Is this okay?
Code:char *buffer; string windowtext; int winlength=GetWindowTextLength(loggedin[5]); buffer=(char*)malloc(winlength); GetWindowText(loggedin[5],buffer,winlength); windowtext.insert(FileContents.length(),buffer,winlength); free(buffer);
"The Internet treats censorship as damage and routes around it." - John Gilmore
Well, it looks to be a mix of c and c++ which is not such a good idea. If it's c-code then you shouldn't have to cast the return value from malloc. If you want to use dynamic memory allocation with c++ then you should prefer 'new' and 'delete' or 'new[]' and 'delete[] for arrays.
edit: Sorry, I just noticed I forgot to specify the type of std::vector being initialised in my previous post; I've now edited it to correct that omission.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.