Question To extract the GUID with ObjectFromLresult error occurred

ctjh900801

Member
Joined
Aug 30, 2011
Messages
5
Programming Experience
Beginner
API Declarations

<DllImport("oleacc.dll")> _
Shared Function ObjectFromLresult (ByVal lResult As IntPtr, <MarshalAs(UnmanagedType.LPStruct)> ByVal refiid As Guid, ByVal wParam As IntPtr) As <MarshalAs(UnmanagedType.Interface)> Object
End Function






Private Function WDom (ByVal hWnd As IntPtr) As mshtml.IHTMLDocument
Dim L As IntPtr, M As Long
Dim IHTMLDocumentIDAsString As New Guid ("626FC520-A41E-11CF-A731-00A0C9082637")

M = RegisterWindowMessage ("WM_HTML_GETOBJECT")
If M <> 0 Then
SendMessageTimeout (hWnd, M, 0L, 0L, SMTO_ABORTIFHUNG, 1000L, L)
If L <> 0 Then

Return DirectCast (ObjectFromLresult (L, IHTMLDocumentIDAsString, 0), mshtml.IHTMLDocument) <<<'attempt to read or write protected memory. This usually means that other memory is corrupt.
End If
End If
End Function

When I go to extract the GUID with ObjectFromLresultAccessviolationException not occurred at the
Management 'attempt to read or write protected memory. This usually means that other memory is corrupt.
What does the way in here to deal with ObjectFromLresult the API to be successful extraction GUID.
 
AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory has been corrupted.
Usually that means the declaration is wrong.
ObjectFromLresult Function (Windows)
According to this your current return type is to be a fourth ByRef parameter. Which I also tested and it works that way. It may have been different in the past.
You're also using Longs several places, which seems weird, usually it is Integer or IntPtr.

ObjectFromLresult is an internal function though. Another (simpler) approach to get the document object is SHDocVw.ShellWindows from MS Internet Controls library.
 
Hi,
According to your statement mean that ObjectFromLresult can not handle this problem out?
Is there a way to change its statement to help me complete the action here, because I'm not very good at changing API
I refer here to all thehttp://pinvoke.net/default.aspx/oleacc/ObjectFromLresult.html

Then if ObjectFromLresult not complete the action here, whether I candemonstrate what's on your
The second method SHDocVw.ShellWindows from MS Internet Controls library.

Which I used to extract Messenger conversation window text out.
This is my purpose.
I was the first written reference to the method in VB6.
Then here come the application to VB.NET.

Here is what I had in the VB6 code:
'---------------------------------------
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type






Private Const WM_GETTEXT = &HD
Private Const SMTO_ABORTIFHUNG = &H2
Private Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, riid As UUID, ByVal wParam As Long, ppvObject As Any) As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Any, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Sub Timer1_Timer()

On Error Resume Next

Dim Hwn As Long, rHw As Long, S As String, Obj As HTMLDocument


Dim STemp(0) As String
Dim hWnd2 As Long
Dim hwnd5 As Long
Dim hwnd3 As Long
Dim hwnd4 As Long


hWnd2 = GetDesktopWindow()
hwnd5 = FindWindowEx(hWnd2, 0, "CConvWndBase", vbNullString)
hwnd3 = FindWindowEx(hwnd5, 0, "YHTMLContainer", vbNullString)
hwnd4 = FindWindowEx(hwnd3, 0, "Internet Explorer_Server", vbNullString)

If hwnd4 <> 0 Then
Set Obj = WDom(hwnd4)
If Not (Obj Is Nothing) Then
Text1(0) = Obj.body.innerText
End If
Else
Text1(0) = ""


End If
End Sub


'Internet Explorer_Server
Private Function WDom(ByVal hWnd As Long) As IHTMLDocument
Dim U As UUID, L As Long, M As Long
M = RegisterWindowMessage("WM_HTML_GETOBJECT")
If M <> 0 Then
SendMessageTimeout hWnd, M, 0, 0, SMTO_ABORTIFHUNG, 1000, L
If L <> 0 Then
With U
.Data1 = &H626FC520: .Data2 = &HA41E
.Data3 = &H11CF: .Data4(0) = &HA7
.Data4(1) = &H31: .Data4(2) = &H0
.Data4(3) = &HA0: .Data4(4) = &HC9
.Data4(5) = &H8: .Data4(6) = &H26
.Data4(7) = &H37
End With
ObjectFromLresult L, U, 0, WDom
End If
End If
End Function

'----------------------------------------------


Here there is a change is on ObjectFromLresult UUID into a GUID.
Here may be brought out this problem from occurring conditions.
I hope to be given under the guidance here.
 
Last edited:
Back
Top