EM_REQUESTRESIZE message produces Access Denied error

aaaron123@roadrunner.com

Well-known member
Joined
Jan 23, 2011
Messages
47
Programming Experience
10+
I wrote a RichTextBox-based app years ago and it works well. I recently found out that something is not quite right although it hasn't caused m any problems untill I used a very very large text.
I've collected the relative code from my app (the app is very large):

VB.NET:
  Public Declare Auto Function SendMessage Lib "user32.dll" (hWnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
    Public Const WM_USER As Integer = &H400
    Public Const EM_REQUESTRESIZE As Integer = WM_USER + 65
    Private Sub RequestSizeFromTxtControl()
        'EM_REQUESTRESIZE message: Forces a rich edit control to send an EN_REQUESTRESIZE notification code to its parent window
        'Try
        SendMessage(RichTextBox_Txt.Handle, EM_REQUESTRESIZE, IntPtr.Zero, IntPtr.Zero)
        'Catch
        Dim ex As Win32Exception = New Win32Exception(Marshal.GetLastWin32Error())
        TxtAppendLine("Native EM_REQUESTRESIZE Error: " & ex.NativeErrorCode & vbCrLf & ex.Message & vbCrLf)
        'End Try
    End Sub

With the error checking (recently added) I get the following:

Native EM_REQUESTRESIZE Error: 5
Access is denied

Native EM_REQUESTRESIZE Error: 5
Access is denied

Native EM_REQUESTRESIZE Error: 5
Access is denied


That happens before I enter text so it's not related to having much text.
I do many other messages with the same handle so I can't imagine what is causing the denied message.

If you can't tell me what is probably wrong in the code can you give me any suggestions as to experiment I could perform?
 
Last edited by a moderator:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,412
Location
Norway
Programming Experience
10+
This appears relevant: SendMessage function (winuser.h) - Win32 apps
When a message is blocked by UIPI the last error, retrieved with GetLastError, is set to 5 (access denied).
BUT - when I tested the code within current process I also get the 'access denied', and the request still worked and returned a correct EN_REQUESTRESIZE notification.

Someone reported similar on twitter:
It seems there is some kind of problem with UIPI in Windows. When you SendMessage from a low integrity process, even UIPI allows some kind of messages like WM_GETTEXT but it still set 0x5 (access denied) in GetLastError().
 
Top Bottom