- This topic has 29 replies, 3 voices, and was last updated 9 years ago by Chike.
-
AuthorPosts
-
November 29, 2014 at 11:32 pm #190551pharaonMember
I’m using this code to get pal room text
I’m using vs2013 and nerframework 4
the problem is it’s some times retrieve the text and other times not I tried to breakpoint so every thing go fine but still some times it retrieve text after I breakpoint and sometimes when I restart the application it just retrieve empty string “”
what could cause that issue and how to fix
Declare Function SendMessageA Lib "USER32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As StringBuilder) As Integer Call SendMessageA(hwnd, EM_GETLINE, (iLastLine - 2), strBuffer)
November 29, 2014 at 11:45 pm #190580ChikeMemberDoes it happen in small quiet room or big busy rooms?
November 30, 2014 at 8:41 am #190579pharaonMemberit happen in both
some time I tried it in even a private room
I start the application it just retrieve empty string. Then I close and restart it work fine
so I don’t know what cause the problem to make it retrieve empty string
November 30, 2014 at 4:24 pm #190578ChikeMemberIts probably not the SendMessageA, check that you have the hwnd correctly
November 30, 2014 at 5:17 pm #190577pharaonMemberi have the hwnd correctly
the strange thing is today I tried it so it retrieve some lines and other lines it give me empty string, I didn’t even restart the program while it still working some times it retrieve the text and some times it just give empty
I don’t know why
November 30, 2014 at 6:59 pm #190576pharaonMemberok I kind of fix it I just had to dim the StringBuilder in right way I did that
Dim strBuffer As New StringBuilder(" ", 1024)
the new issue now is that it get part of the line not the whole line exactly 32 letter
November 30, 2014 at 7:10 pm #190575ChikeMemberLet me guess, you get a maximum of 32 charaters?
You might want to read the documentation for EM_GETLINE, you might have saved yourself the trouble if you searched the forums, this not the first time this issue is asked.November 30, 2014 at 7:28 pm #190574pharaonMemberI read it but didn’t understand it quite
can you give me the link in the forum that discuss this topic
November 30, 2014 at 7:36 pm #190573ChikeMemberDim strBuffer As New StringBuilder(1024) strBuffer.Append(1024)
November 30, 2014 at 7:42 pm #190572pharaonMembernow it just get 49 letter
November 30, 2014 at 8:22 pm #190571pharaonMemberok now I know what is the problem
it’s the net framework version it have to be 3.5
when it’s 3.5 every thing work just fine
but when it’s 4 it doesn’t work and my app have to be net framework 4
so is there any way to fix this?
November 30, 2014 at 8:28 pm #190570ChikeMembernow it just get 49 letter
Sorry
strBuffer.Append(ChrW(1024))
ok now I know what is the problem
it’s the net framework version it have to be 3.5
when it’s 3.5 every thing work just fine
but when it’s 4 it doesn’t work and my app have to be net framework 4
so is there any way to fix this?No this is not the problem
November 30, 2014 at 8:39 pm #190569pharaonMembernow it get just 63 letter
November 30, 2014 at 9:29 pm #190568ChikeMemberTry declaring SendMessage
Declare Auto Function SendMessage Lib "USER32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As StringBuilder) As Integer
December 1, 2014 at 2:59 am #190567ChikeMemberThe problem is with marshaling.
for ansi the code should be
strBuffer.Append(Chr(1024 And 255)) strBuffer.Append(Chr(1024 / 256))
Because the buffer is marshaled from unicode to anso on it’s way out Char by Char. 1024 fits in a Char which is 2 byte unicode but when marshaled the high byte is lost. or somehow converted
I suggest to declare and use SendMessage as follows, since the edit control is unicode anyway
Declare Unicode Function SendMessage Lib “USER32” Alias “SendMessageW” _
(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer,
ByVal lParam As StringBuilder) As IntegerstrBuffer.Append(ChrW(1024))
-
AuthorPosts
Related
- You must be logged in to reply to this topic.