 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Fri Dec 03, 2010 9:02 am Post subject: ListView Problem |
|
|
I'm creating a function to add items into colums, this is what I've
Code: | void InsertLVItem(std::string First,std::string Sec,std::string Third)
{
LVITEM lvi;
ZeroMemory(&lvi, sizeof(lvi));
lvi.mask = LVIF_TEXT;
lvi.iItem = SendMessage(hListControl, LVM_GETITEMCOUNT, 0, 0);
lvi.iSubItem = 0;
[b]lvi.pszText = One;[/b]
lvi.cchTextMax = lstrlen(lvi.pszText) + 1;
ListView_InsertItem(hListControl, &lvi);
lvi.iSubItem = 1;
[b]lvi.pszText =Two;[/b]
SendMessage(hListControl, LVM_SETITEM, 0, (LPARAM) &lvi);
lvi.iSubItem = 2;
[b]lvi.pszText =Three;[/b]
SendMessage(hListControl, LVM_SETITEM, 0, (LPARAM) &lvi);
} |
I can't assign a std::string value to a LPWSTR one. I use unicdode (does it matter, or is multy byte better?). I tried a lot of things to change std::string to LPWSTR, but no succes. Is there not a way to change lvi.psztext to std::string or something.
Or a good way to change std::string to LPWSTR. Or is it bad to use std::string?
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Dec 03, 2010 9:06 am Post subject: |
|
|
I don't actually program C++ but I guess you could use string::c_str ? It would not be LPWSTR, it would be LPCSTR. You could convert it afterwards with MultiByteToWideChar(). I think you might even be able to convert from std::string straight to LPWSTR with that API.
The method I mention is definitely doable but I am sure there is a better way. Again, I don't program C++..
|
|
Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Fri Dec 03, 2010 9:28 am Post subject: |
|
|
void InsertLVItem(std::string First,std::string Sec,std::string Third)
{
LVITEM lvi;
LPCSTR y =First.c_str();
LPWSTR x;
SecureZeroMemory(x,20);
MultiByteToWideChar(CP_ACP,MB_COMPOSITE,y,20,x,20);
Thanks, but I keep getting x is used without being intiziliated, so I tried SecureZeroMemory and also x = ""'; but no succes.
EDIT: I've fixed it, maybe not very good but it works, if someone know something better post please.
void InsertLVItem(std::string First,std::string Sec,std::string Third)
{
LVITEM lvi;
LPCSTR y =First.c_str();
wchar_t x[20];
//SecureZeroMemory(x,20);
//MultiByteToWideChar(CP_ACP,MB_COMPOSITE,y,20,x,20);
mbstowcs(x,y,20);
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Dec 03, 2010 9:37 am Post subject: |
|
|
LPWSTR = long pointer to widechar string. You are simply declaring a 4/8 byte pointer. Use string::length to determine length of the string and declare an array of widechars appropriately. LPWSTR is essentially a pointer to an array. You have not initialised it with anything. It's even worse that you've used SecureZeroMemory in this case. You are basically forcing a buffer overflow..
In response to your edit, you should never hardcode string lengths in these sorts of situations. Either pass it in as a parameter or call the string's length() method. What you have done is a dangerous and bad practice.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Sat Dec 04, 2010 9:11 am Post subject: |
|
|
Use std::wstring for wide-char variation of the string library.
_________________
- Retired. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|