Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ EM_GETLINE problem

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Thu Jun 12, 2008 7:54 am    Post subject: C++ EM_GETLINE problem Reply with quote

Code:
   
       int numoflines;
   string temp;
   TCHAR teststring[128];

   numoflines = SendMessage(ScriptWin, EM_GETLINECOUNT, 0, 0);

   temp = SendMessage(ScriptWin, EM_GETLINE, 1, (LPARAM)&teststring);

   SendMessage(OutputWin, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)teststring);


Ya...I, trying to put the string into the buffer....and then display it in another window....but sometimes i get random characters after what i put in the first edit box.

Example:

I put "Hello my name is Bob" in the first box.
Then, after this code executes, in the second box it says something like
"Hello my name is BobX*"
Back to top
View user's profile Send private message Send e-mail
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Thu Jun 12, 2008 8:04 am    Post subject: Reply with quote

Be sure to null-terminate the string.
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Thu Jun 12, 2008 8:07 am    Post subject: Reply with quote

Renkokuken wrote:
Be sure to null-terminate the string.


Pardon me? What does that mean?
Back to top
View user's profile Send private message Send e-mail
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Thu Jun 12, 2008 8:10 am    Post subject: Reply with quote

http://en.wikipedia.org/wiki/Null_character
http://www.cplusplus.com/doc/tutorial/ntcs.html

I'll explain it further if you don't get it from these sources.

Also: Other reasons could be writing outside of the array size, and writing a length that exceeds that of the array.
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Thu Jun 12, 2008 8:28 am    Post subject: Reply with quote

I get it....but I don't know how to use it so it works with TCHAR
Back to top
View user's profile Send private message Send e-mail
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Thu Jun 12, 2008 8:29 am    Post subject: Reply with quote

kitterz wrote:
I get it....but I don't know how to use it so it works with TCHAR
TCHAR is just a definition of either char or wchar_t, depending on the character set of the solution.

Last edited by Renkokuken on Thu Jun 12, 2008 8:34 am; edited 1 time in total
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Thu Jun 12, 2008 8:32 am    Post subject: Reply with quote

hmmm im using amulti-byte char set
Back to top
View user's profile Send private message Send e-mail
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Thu Jun 12, 2008 8:34 am    Post subject: Reply with quote

kitterz wrote:
hmmm im using amulti-byte char set
TCHAR is just char then.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jun 12, 2008 8:37 am    Post subject: Reply with quote

The return value of the message EM_GETLINE is the number of TCHAR's copied to the buffer.

Code:
TCHAR tszString[256];
int nLines = SendMessage(ScriptWin, EM_GETLINECOUNT, 0, 0);
int nLength = SendMessage(ScriptWin, EM_GETLINE, 1, (LPARAM)tszString);
tszString[nLength+1] = '\0';
SendMessage(OutputWin, WM_SETTEXT, 0, (LPARAM)tszString);


Also, don't forget the wParam in EM_GETLINE is a zero-based index of the lines. so 1 is the second line.

_________________
Back to top
View user's profile Send private message
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Thu Jun 12, 2008 8:38 am    Post subject: Reply with quote

Hhaha, I was trying to have him solve it on his own, but that works out fine either way.
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Thu Jun 12, 2008 8:41 am    Post subject: Reply with quote

Thanks you're the best!

@ Renkokuken i did solve it on my own b4 lurc came in but thx lurc annyways!
Back to top
View user's profile Send private message Send e-mail
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Thu Jun 12, 2008 8:45 am    Post subject: Reply with quote

Glad to hear it's working, and good luck with the rest of the project.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites