Skip to content

problem with SendMessageA

Viewing 15 posts - 1 through 15 (of 30 total)
  • Author
    Posts
  • #190551
    pharaon
    Member

    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)

     

    #190580
    Chike
    Member

    Does it happen in small quiet room or big busy rooms?

    #190579
    pharaon
    Member

    it 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

    #190578
    Chike
    Member

    Its probably not the SendMessageA, check that you have the hwnd correctly

    #190577
    pharaon
    Member

    i 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

    #190576
    pharaon
    Member

    ok 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

     

    #190575
    Chike
    Member

    Let 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.

    #190574
    pharaon
    Member

    I read it but didn’t understand it quite

    can you give me the link in the forum that discuss this topic

    #190573
    Chike
    Member
    Dim strBuffer As New StringBuilder(1024)
    strBuffer.Append(1024)
    #190572
    pharaon
    Member

    now it just get 49 letter

    #190571
    pharaon
    Member

    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?

    #190570
    Chike
    Member

    now 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

    #190569
    pharaon
    Member

    now it get just 63 letter

    #190568
    Chike
    Member

    Try 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

     

    #190567
    Chike
    Member

    The 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 Integer

    strBuffer.Append(ChrW(1024))

Viewing 15 posts - 1 through 15 (of 30 total)
  • You must be logged in to reply to this topic.