|
i know i would have to use apis but the only thing i can find for this is in vb6 or vc++ but nuttin for vb2008
i do know that LB_GETTEXT dont work
i do know how to find the window to the listbox, but just cant get the text from the listbox | | Tiger39m9 Thursday, October 22, 2009 4:43 AM | well i could not get it to work in .net like i need it been working on this problem for a long time about 4 mounths
so going to stop working on this part for now but a little good news tho
i made the program in vb6 to get the listbox items that i need, and move that text to a textbox in the same program in vb6. so now the text that i need is in a window that i can get easly.
its a round about way of doing what i need, but it works. - Marked As Answer byTiger39m9 Friday, November 06, 2009 6:44 PM
-
| | Tiger39m9 Friday, November 06, 2009 6:44 PM | So are you trying to run this code from a Visual Basic .NET app or are you trying to get the text from a ListBox of a Visual Basic .NET app?
You are correct though in that you would still use Windows API function calls. Paul ~~~~ Microsoft MVP (Visual Basic) | | Paul P Clement IV Thursday, October 22, 2009 1:32 PM | i am running this code from vb2008
the text i am trying to get is from and outside application
i can find the window to the listbox with ease
from what i read about doing this is that u have to open a process to the memory to get the text
but that is from vb6 i have tried that out and works very good but that is vb6 and in .net is very differnt
there is no exsamples or anythng about this in .net on howto do this type of work i have been working on this for 3 mounths with no progress i have even tryied to convert the vb6 to .net but with no luck | | Tiger39m9 Thursday, October 22, 2009 2:44 PM | Please have a look this code sample to fetch text from Notepad. First use Findwindow to get parent window's handle. Then use FindWindowEx to get child control's handle. Imports System.IO Imports System.Runtime.InteropServices Imports System.Text Public Class Form1 Const WM_GETTEXTLENGTH = &HE Const WM_GETTEXT = &HD <DllImport("USER32.DLL", CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _ Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr End Function <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _ ByVal childAfter As IntPtr, _ ByVal lclassName As String, _ ByVal windowTitle As String) As IntPtr End Function <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function SendMessage(ByVal hWnd As IntPtr, _ ByVal Msg As UInteger, _ ByVal wParam As IntPtr, _ ByVal lParam As IntPtr) As Int32 End Function Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, _ ByVal wparam As Integer, ByVal lparam As System.Text.StringBuilder) As IntPtr Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim notepadHandle As IntPtr notepadHandle = FindWindow("Notepad", Nothing) Dim childhandle As IntPtr = FindWindowEx(notepadHandle, IntPtr.Zero, "Edit", Nothing) If notepadHandle = IntPtr.Zero Then MessageBox.Show("can't find") Else MessageBox.Show(childhandle.ToString) MessageBox.Show(WindowText(childhandle)) End If End Sub Public Function WindowText(ByVal window_hwnd As IntPtr) As String Dim txtlen As Int32 WindowText = "" If window_hwnd = 0 Then Exit Function txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, _ 0) If txtlen = 0 Then Exit Function txtlen = txtlen + 1 Dim txt As StringBuilder = New StringBuilder(txtlen) SendMessage(window_hwnd, WM_GETTEXT, txtlen, txt) WindowText = txt.ToString End Function End Class
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Riquel_Dong Friday, October 23, 2009 7:50 AM | i know how to get the text from a window, but this is all differnt i am trying to get the text of items in a listbox
now i did convert this code from vb6 to .net
here is all the code i have for it so far
Imports System.Text Imports System.Runtime.InteropServices Imports System.Diagnostics Imports Microsoft.VisualBasic Imports System.Security.Permissions
Module Module1
Public Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Int32, ByVal bInheritHandle As Int32, ByVal dwProcId As Int32) As Int32 Public Declare Function GetTokenInformation Lib "advapi32.dll" (ByVal TokenHandle As IntPtr, ByVal TokenInformationClass As TOKEN_INFORMATION_CLASS, ByVal TokenInformation As IntPtr, ByVal TokenInformationLength As System.UInt32, ByRef ReturnLength As System.UInt32) As Boolean <DllImport("advapi32.dll", SetLastError:=True)> Public Function OpenProcessToken(ByVal ProcessHandle As IntPtr, ByVal DesiredAccess As Integer, ByRef TokenHandle As IntPtr) As Boolean End Function Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Object, ByVal Source As Object, ByVal Length As Long) Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal blnheritHandle As Boolean, ByVal dwAppProcessId As Integer) As Integer Public Declare Function OpenThreadToken Lib "advapi32.dll" (ByVal ThreadHandle As IntPtr, ByVal DesiredAccess As Integer, ByVal OpenAsSelf As Boolean, ByRef TokenHandle As IntPtr) As Boolean Public Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Integer, ByVal DesiredAccess As Integer, ByVal TokenHandle As Integer) As Integer Public Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByVal lpLuid As Luid) As Long
Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
<DllImport("kernel32.dll")> Public Function OpenProcess(ByVal dwDesiredAccess As ProcessAccessFlags, <MarshalAs(UnmanagedType.Bool)> ByVal bInheritHandle As Boolean, ByVal dwProcessId As Integer) As IntPtr End Function <DllImport("user32.dll", SetLastError:=True)> Public Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer End Function
Friend Sub CopyMemory(ByVal Destination As IntPtr, ByVal Source As IntPtr, ByVal Length As UInteger) End Sub
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer
Public Enum ProcessAccessFlags As Integer CreateThread = &H2 DuplicateHandle = &H40 QueryInformation = &H400 SetInformation = &H200 Terminate = &H1 VMOperation = &H8 VMRead = &H10 VMWrite = &H20 Synchronize = &H100000 READ_CONTROL = &H20000 STANDARD_RIGHTS_REQUIRED = &HF0000 STANDARD_RIGHTS_READ = READ_CONTROL STANDARD_RIGHTS_WRITE = READ_CONTROL STANDARD_RIGHTS_EXECUTE = READ_CONTROL STANDARD_RIGHTS_ALL = &H1F0000 SPECIFIC_RIGHTS_ALL = &HFFFF TOKEN_ASSIGN_PRIMARY = &H1 TOKEN_DUPLICATE = &H2 TOKEN_IMPERSONATE = &H4 TOKEN_QUERY = &H8 TOKEN_QUERY_SOURCE = &H10 TOKEN_ADJUST_PRIVILEGES = &H20 TOKEN_ADJUST_GROUPS = &H40 TOKEN_ADJUST_DEFAULT = &H80 TOKEN_ADJUST_SESSIONID = &H100
End Enum Enum TOKEN_INFORMATION_CLASS
TokenUser = 1 TokenGroups TokenPrivileges TokenOwner TokenPrimaryGroup TokenDefaultDacl TokenSource TokenType TokenImpersonationLevel TokenStatistics TokenRestrictedSids TokenSessionId TokenGroupsAndPrivileges TokenSessionReference TokenSandBoxInert TokenAuditPolicy TokenOrigin TokenElevationType TokenLinkedToken TokenElevation TokenHasRestrictions TokenAccessInformation TokenVirtualizationAllowed TokenVirtualizationEnabled TokenIntegrityLevel TokenUIAccess TokenMandatoryPolicy TokenLogonSid MaxTokenInfoClass
End Enum Private Structure SID_AND_ATTRIBUTES Dim Sid As Integer Dim Attributes As Integer End Structure
Private Structure TOKEN_GROUPS Dim GroupCount As Integer Dim Groups() As SID_AND_ATTRIBUTES End Structure
Private Const READ_CONTROL As Integer = &H20000 Private Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000 Private Const STANDARD_RIGHTS_READ As Integer = READ_CONTROL Private Const STANDARD_RIGHTS_WRITE As Integer = READ_CONTROL Private Const STANDARD_RIGHTS_EXECUTE As Integer = READ_CONTROL Private Const STANDARD_RIGHTS_ALL As Integer = &H1F0000 Private Const SPECIFIC_RIGHTS_ALL As Integer = &HFFFF Private Const TOKEN_ASSIGN_PRIMARY As Integer = &H1 Private Const TOKEN_DUPLICATE As Integer = &H2 Private Const TOKEN_IMPERSONATE As Integer = &H4 Private Const TOKEN_QUERY As Integer = &H8 Private Const TOKEN_QUERY_SOURCE As Integer = &H10 Private Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20 Private Const TOKEN_ADJUST_GROUPS As Integer = &H40 Private Const TOKEN_ADJUST_DEFAULT As Integer = &H80 Private Const TOKEN_ADJUST_SESSIONID As Integer = &H100
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Public Declare Function FindWindowA Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpszl As String, ByVal lpsz2 As String) As Integer Public Declare Function FindWindowExA Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpszl As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Public Declare Function SendMessagea Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Integer Public Declare Function SendMessagea Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Integer) As Long
Public Declare Function SendIt& Lib "user32" Alias "SendMessageA" (ByVal hwnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam As String) Public Declare Function SendIt& Lib "user32" Alias "SendMessageA" (ByVal hwnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam As Integer) Public Declare Function SendItByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam$)
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Public Declare Function SendMessageLongA Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendDialogMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer Public Declare Function SendMessageByStringA Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hWnd As Long) As Long Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Integer, ByVal wMsg As String, ByVal wparam As Integer, ByVal lParam As String) As Integer
Public Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
'Message API Decs 'Menu API Decs 'INI Read/Write API Decs 'Misc. API Decs
'Public Constants for use with API Decs Public Const BM_SETCHECK = &HF1 Public Const BM_GETCHECK = &HF0
Public Const HWND_NOTOPMOST = -2 Public Const HWND_TOPMOST = -1
Public Const CB_GETCOUNT = &H146 Public Const CB_GETLBTEXT = &H148 Public Const CB_SETCURSEL = &H14E Public Const CB_GETITEMDATA = &H150
Public Const GW_HWNDFIRST = 0 Public Const GW_HWNDNEXT = 2 Public Const GW_CHILD = 5
Public Const LB_GETCOUNT = &H18B Public Const LB_GETTEXT = &H189 Public Const LB_GETTEXTLEN = &H18A Public Const LB_SETCURSEL = &H186 Public Const LB_GETITEMDATA = &H199
Public Const SW_HIDE = 0 Public Const SW_MAXIMIZE = 3 Public Const SW_MINIMIZE = 6 Public Const SW_NORMAL = 1 Public Const SW_SHOW = 5
Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1
Public Const VK_SPACE = &H20 Public Const VK_DOWN = &H28 Public Const VK_RETURN = &HD
Public Const WM_CHAR = &H102 Public Const WM_CLOSE = &H10 Public Const WM_COMMAND = &H111 Public Const WM_GETTEXT = &HD Public Const WM_GETTEXTLENGTH = &HE Public Const WM_KEYDOWN = &H100 Public Const WM_KEYUP = &H101 Public Const WM_LBUTTONDBLCLK = &H203 Public Const WM_LBUTTONDOWN = &H201 Public Const WM_LBUTTONUP = &H202 Public Const WM_MOVE = &HF012 Public Const WM_RBUTTONDOWN = &H204 Public Const WM_RBUTTONUP = &H205 Public Const WM_SETTEXT = &HC Public Const WM_SYSCOMMAND = &H112 Public Const WM_USER = &H400 Public Const PROCESS_QUERY_INFORMATION = 1024 Public Const PROCESS_VM_READ = 16
Public Const PROCESS_READ = &H10
Public Const RIGHTS_REQUIRED = &HF0000
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Public Const PROCESS_ALL_ACCESS = &H1F0FFF Public Const PAGE_READWRITE = &H4
Public AOLChild As Integer Public AOLFrame As Integer Public MDIClient As Integer Public AOLList As Integer Structure LARGE_INTEGER Dim lowpart As Integer Dim highpart As Integer End Structure
Structure Luid Dim lowpart As Integer Dim highpart As Integer End Structure
Structure LUID_AND_ATTRIBUTES Dim pLuid As Luid Dim Attributes As Integer End Structure
Structure TOKEN_PRIVILEGES Dim PrivilegeCount As Integer Dim Privileges() As LUID_AND_ATTRIBUTES End Structure
rem converted from vb6
Public Function AddAOL8ListToList(ByVal ListToGet As Integer, ByVal ListToAddTo As ListBox, Optional ByVal AddUser As Boolean = False)
On Error Resume Next
Dim cProcess As Integer, itmHold As Integer, ScreenName As String Dim psnHold As Integer, rBytes As Integer, Index As Integer Dim sThread As Integer, mThread As Integer
sThread = GetWindowThreadProcessId(ListToGet, cProcess)
'this 'OpenProcess' API Call allows for us to read the contents of the 'listbox in a nonconventional way, since conventional methods dont work :) 'We will read that tasks of the window (thread) into mThread& Debug.WriteLine("GetWindowThreadProcessId Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error) Debug.WriteLine("GetWindowThreadProcessId sThread: " & sThread) Debug.WriteLine("GetWindowThreadProcessId cProcess: " & cProcess)
mThread = OpenProcess(PROCESS_READ Or RIGHTS_REQUIRED, False, cProcess)
'If its valid, then commence adding Debug.WriteLine("OpenProcess Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error) Debug.WriteLine("OpenProcess mThread: " & mThread)
If mThread Then 'Loop through the list items using my ListCount Procedure 'We must subtract 1 since its zero-based For Index = 0 To ListCount(ListToGet) - 1 'Get the current screen name -the invalid characters ScreenName = New String(vbNullChar, 4) 'Get's the screen name from the list through itmHold&
itmHold = SendMessage(ListToGet, LB_GETITEMDATA, CInt(Index), 0)
itmHold = itmHold + 28 'Read the data from itmHold with the ReadProcessMemory API Call, 'this will enable us to get the actual data via the "non-conventional" way :) 'heh, trying to explain as simple as possible.. basically its reading the data 'in a special way into th memory
Call ReadProcessMemory(mThread, itmHold, ScreenName, 4, rBytes) Debug.WriteLine("ReadProcessMemory1 Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error)
'Now we will read that memory-added data Call CopyMemory(psnHold, ScreenName, 4) Debug.WriteLine("CopyMemory Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error)
psnHold = psnHold + 6
'Subtract invalid characters ScreenName = New String(vbNullChar, 16) 'Read into memory again Call ReadProcessMemory(mThread, psnHold, ScreenName, Len(ScreenName), rBytes) Debug.WriteLine("ReadProcessMemory2 Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error)
'Finally, we've got our SN ScreenName = Left(ScreenName, InStr(ScreenName, vbNullChar) - 1) 'Make sure, if the user doesn't want to add the actual user, then 'dont add to list, otherwise, add :) If ScreenName <> GetUser() Or AddUser = True Then ListToAddTo.Items.Add(ScreenName) End If 'Move on to next SN :) Next Index 'Close the processed memory thread Call CloseHandle(mThread) Debug.WriteLine("CloseHandle Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error)
End If
End Function Public Function FindWelcomeWin() As Integer Dim aolframe As Integer, mdiclient As Integer, aolchild As Integer aolframe = FindWindow("AOL Frame25", vbNullString) mdiclient = FindWindowEx(aolframe, 0, "MDIClient", vbNullString) aolchild = FindWindowEx(mdiclient, 0, "AOL Child", vbNullString) aolchild = FindWindowEx(mdiclient, aolchild, "AOL Child", vbNullString) Dim Winkid1 As Integer, Winkid2 As Integer, Winkid3 As Long, Winkid4 As Integer, Winkid5 As Integer, Winkid6 As Integer, Winkid7 As Integer, Winkid8 As Integer, Winkid9 As Integer, FindOtherWin As Integer FindOtherWin = GetWindow(aolchild, GW_HWNDFIRST)
Do While FindOtherWin <> 0
Winkid1 = FindWindowEx(FindOtherWin, 0, "_aol_icon", vbNullString) Winkid2 = FindWindowEx(FindOtherWin, 0, "_aol_glyph", vbNullString) Winkid3 = FindWindowEx(FindOtherWin, 0, "_aol_icon", vbNullString) Winkid4 = FindWindowEx(FindOtherWin, 0, "_aol_glyph", vbNullString) Winkid5 = FindWindowEx(FindOtherWin, 0, "richcntlstatic", vbNullString) Winkid6 = FindWindowEx(FindOtherWin, 0, "_aol_glyph", vbNullString) Winkid7 = FindWindowEx(FindOtherWin, 0, "_aol_icon", vbNullString) Winkid8 = FindWindowEx(FindOtherWin, 0, "_aol_glyph", vbNullString) Winkid9 = FindWindowEx(FindOtherWin, 0, "richcntlstatic", vbNullString) If (Winkid1 <> 0) And (Winkid2 <> 0) And (Winkid3 <> 0) And (Winkid4 <> 0) And (Winkid5 <> 0) And (Winkid6 <> 0) And (Winkid7 <> 0) And (Winkid8 <> 0) And (Winkid9 <> 0) Then FindWelcomeWin = FindOtherWin Exit Function End If FindOtherWin = GetWindow(FindOtherWin, GW_HWNDNEXT)
Loop FindWelcomeWin = 0 ' example on how to use: ' ' Dim TheWin As Long ' TheWin = FindWelcomeWin() ' ' If TheWin <> 0 Then ' User is online since there is a WelcomeWin ' End If End Function Public Function GetUser() As String Dim strUserSN As String, lngWelcWin As Integer lngWelcWin = FindWelcomeWin() If lngWelcWin = 0 Then 'user is not even online GetUser = "[not online]" 'return "[not online]" Else strUserSN = GetText(FindWelcomeWin) strUserSN = Replace(strUserSN, "Welcome, ", "") 'Remove "Welcome, " GetUser = Replace(strUserSN, "!", "") 'Remove "!" and return End If End Function Public Function GetText(ByVal hWnd As Integer) Dim TheText As String, TL As Integer TL = SendMessageLong(hWnd, WM_GETTEXTLENGTH, 0, 0) TheText = New String(" ", TL + 1) Call SendMessageByString(hWnd, WM_GETTEXT, TL + 1, TheText) GetText = Left(TheText, TL)
End Function Public Function ListCount(ByVal ListBox As Integer) As Integer ListCount = SendMessageLong(ListBox, LB_GETCOUNT, 0, 0)
End Function
ok this is the errors that it gives me
GetWindowThreadProcessId Error: 0 GetWindowThreadProcessId sThread: 3500 GetWindowThreadProcessId cProcess: 5004 OpenProcess Error: 1008 OpenProcess mThread: 1540 ReadProcessMemory1 Error: 1008 CopyMemory Error: 0 ReadProcessMemory2 Error: 299 CloseHandle Error: 2
| | Tiger39m9 Friday, October 23, 2009 8:20 AM | Hi , I think that ListBox should be drawn by WM_Text windows message. If I am right, using SendMessage to fetch the text is one very easy method. If you want to open the process and read the data from the memory. Do you know whether ListBox text information is saved in the memory?
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Riquel_Dong Friday, October 23, 2009 8:58 AM | u cant read text from a listbox using WM_Text i just tried it and no go
and from what i read all over the net u have toread it from the memory
u have to read it from memory
in the above code i sent in
OpenProcess Error: 1008 this error tells me no token i have never messed with tokens before i have read a lot about it but dont know how to do it
i am under admin with uac disabled and still gives me this error | | Tiger39m9 Friday, October 23, 2009 9:33 AM | Researching this a bit LB_GETTEXT is what you should be using. There is a Classic VB example at the below link: http://www.vbforums.com/showthread.php?t=85604Now there is a limitation. The ListBox must support the LBS_HASSTRINGS style. If not, then the ListBox items are probably stored internally and you probably won't be able to fetch them.AFAIK, using SendMessage withLB_GETTEXT should function across process boundaries.
Paul ~~~~ Microsoft MVP (Visual Basic) | | Paul P Clement IV Friday, October 23, 2009 12:59 PM | i have tried LB_Gettext and it dont work either
what i will do is give all the vb6 code for this i have and when i use the vb6 code it dose give me the text that i need but i want to get it in .net not vb6
here is the original code for vb6 that works and gets the text that i want
Public Declare Function EnableWindow Lib "user32" (ByVal hWnd As Long, ByVal fEnable As Long) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public 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 Public Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Public Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long 'Process API Decs Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long 'Message API Decs Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Public Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) 'Menu API Decs Public Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long Public Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long 'INI Read/Write API Decs Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long 'Misc. API Decs Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (destination As Any, source As Any, ByVal Length As Long) Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
'Public Constants for use with API Decs Public Const BM_SETCHECK = &HF1 Public Const BM_GETCHECK = &HF0
Public Const HWND_NOTOPMOST = -2 Public Const HWND_TOPMOST = -1
Public Const CB_GETCOUNT = &H146 Public Const CB_GETLBTEXT = &H148 Public Const CB_SETCURSEL = &H14E Public Const CB_GETITEMDATA = &H150
Public Const GW_HWNDFIRST = 0 Public Const GW_HWNDNEXT = 2 Public Const GW_CHILD = 5
Public Const LB_GETCOUNT = &H18B Public Const LB_GETTEXT = &H189 Public Const LB_GETTEXTLEN = &H18A Public Const LB_SETCURSEL = &H186 Public Const LB_GETITEMDATA = &H199
Public Const SW_HIDE = 0 Public Const SW_MAXIMIZE = 3 Public Const SW_MINIMIZE = 6 Public Const SW_NORMAL = 1 Public Const SW_SHOW = 5
Public Const SWP_NOMOVE = &H2 Public Const SWP_NOSIZE = &H1
Public Const VK_SPACE = &H20 Public Const VK_DOWN = &H28 Public Const VK_RETURN = &HD
Public Const WM_CHAR = &H102 Public Const WM_CLOSE = &H10 Public Const WM_COMMAND = &H111 Public Const WM_GETTEXT = &HD Public Const WM_GETTEXTLENGTH = &HE Public Const WM_KEYDOWN = &H100 Public Const WM_KEYUP = &H101 Public Const WM_LBUTTONDBLCLK = &H203 Public Const WM_LBUTTONDOWN = &H201 Public Const WM_LBUTTONUP = &H202 Public Const WM_MOVE = &HF012 Public Const WM_RBUTTONDOWN = &H204 Public Const WM_RBUTTONUP = &H205 Public Const WM_SETTEXT = &HC Public Const WM_SYSCOMMAND = &H112 Public Const WM_USER = &H400
Public Const PROCESS_READ = &H10
Public Const RIGHTS_REQUIRED = &HF0000
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Function FindWelcomeWin() As Long
Dim aolframe As Long, mdiclient As Long, aolchild As Long aolframe = FindWindow("aol frame25", vbNullString) mdiclient = FindWindowEx(aolframe, 0&, "mdiclient", vbNullString) aolchild = FindWindowEx(mdiclient, 0&, "aol child", vbNullString) aolchild = FindWindowEx(mdiclient, aolchild, "aol child", vbNullString) Dim Winkid1 As Long, Winkid2 As Long, Winkid3 As Long, Winkid4 As Long, Winkid5 As Long, Winkid6 As Long, Winkid7 As Long, Winkid8 As Long, Winkid9 As Long, FindOtherWin As Long FindOtherWin = GetWindow(aolchild, GW_HWNDFIRST) Do While FindOtherWin <> 0 DoEvents Winkid1 = FindWindowEx(FindOtherWin, 0&, "_aol_icon", vbNullString) Winkid2 = FindWindowEx(FindOtherWin, 0&, "_aol_glyph", vbNullString) Winkid3 = FindWindowEx(FindOtherWin, 0&, "_aol_icon", vbNullString) Winkid4 = FindWindowEx(FindOtherWin, 0&, "_aol_glyph", vbNullString) Winkid5 = FindWindowEx(FindOtherWin, 0&, "richcntlstatic", vbNullString) Winkid6 = FindWindowEx(FindOtherWin, 0&, "_aol_glyph", vbNullString) Winkid7 = FindWindowEx(FindOtherWin, 0&, "_aol_icon", vbNullString) Winkid8 = FindWindowEx(FindOtherWin, 0&, "_aol_glyph", vbNullString) Winkid9 = FindWindowEx(FindOtherWin, 0&, "richcntlstatic", vbNullString) If (Winkid1 <> 0) And (Winkid2 <> 0) And (Winkid3 <> 0) And (Winkid4 <> 0) And (Winkid5 <> 0) And (Winkid6 <> 0) And (Winkid7 <> 0) And (Winkid8 <> 0) And (Winkid9 <> 0) Then FindWelcomeWin = FindOtherWin Exit Function End If FindOtherWin = GetWindow(FindOtherWin, GW_HWNDNEXT) Loop FindWelcomeWin = 0 ' example on how to use: ' ' Dim TheWin As Long ' TheWin = FindWelcomeWin() ' ' If TheWin <> 0 Then ' User is online since there is a WelcomeWin ' End If End Function
Public Function GetText(hWnd As Long)
Dim TheText As String, TL As Long TL = SendMessageLong(hWnd, WM_GETTEXTLENGTH, 0&, 0&) TheText = String(TL + 1, " ") Call SendMessageByString(hWnd, WM_GETTEXT, TL + 1, TheText) GetText = Left(TheText, TL) End Function
Public Function GetUser() As String
Dim strUserSN As String, lngWelcWin As Long lngWelcWin = FindWelcomeWin If lngWelcWin = 0& Then 'user is not even online GetUser = "[not online]" 'return "[not online]" Else strUserSN = GetText(FindWelcomeWin) strUserSN = Replace(strUserSN, "Welcome, ", "") 'Remove "Welcome, " GetUser = Replace(strUserSN, "!", "") 'Remove "!" and return End If End Function
rem this is the section that reads the listbox
Public Function AddAOL8ListToList(ListToGet As Long, ListToAddTo As ListBox, Optional AddUser As Boolean = False)
On Error Resume Next Dim cProcess As Long, itmHold As Long, ScreenName As String Dim psnHold As Long, rBytes As Long, Index As Long Dim sThread As Long, mThread As Long sThread& = GetWindowThreadProcessId(ListToGet, cProcess&) 'this 'OpenProcess' API Call allows for us to read the contents of the 'listbox in a nonconventional way, since conventional methods dont work :) 'We will read that tasks of the window (thread) into mThread& mThread& = OpenProcess(PROCESS_READ Or RIGHTS_REQUIRED, False, cProcess&) 'If its valid, then commence adding Debug.Print sThread Debug.Print mThread If mThread& Then 'Loop through the list items using my ListCount Procedure 'We must subtract 1 since its zero-based For Index& = 0 To ListCount(ListToGet) - 1 'Get the current screen name -the invalid characters ScreenName$ = String$(4, vbNullChar) 'Get's the screen name from the list through itmHold& itmHold& = SendMessage(ListToGet, LB_GETITEMDATA, ByVal CLng(Index&), ByVal 0&) itmHold& = itmHold& + 28 'Read the data from itmHold with the ReadProcessMemory API Call, 'this will enable us to get the actual data via the "non-conventional" way :) 'heh, trying to explain as simple as possible.. basically its reading the data 'in a special way into th memory Call ReadProcessMemory(mThread&, itmHold&, ScreenName$, 4, rBytes) 'Now we will read that memory-added data Call CopyMemory(psnHold&, ByVal ScreenName$, 4) psnHold& = psnHold& + 6 'Subtract invalid characters ScreenName$ = String$(16, vbNullChar) 'Read into memory again Call ReadProcessMemory(mThread&, psnHold&, ScreenName$, Len(ScreenName$), rBytes&) 'Finally, we've got our SN ScreenName$ = Left$(ScreenName$, InStr(ScreenName$, vbNullChar) - 1) 'Make sure, if the user doesn't want to add the actual user, then 'dont add to list, otherwise, add :) If ScreenName$ <> GetUser$ Or AddUser = True Then ListToAddTo.AddItem ScreenName$ End If 'Move on to next SN :) Next Index& 'Close the processed memory thread Call CloseHandle(mThread) End If End Function
this code works in vb6 not in .net at the very top of my post is the code that i converted over to .net | | Tiger39m9 Friday, October 23, 2009 3:39 PM | I don't know where you encounter a problem in the code but have you checked your API declare statements? I noticed that some them have arguments defined as Long instead of Integer. Remember that a Long in Visual Basic .NET is 64-bits and not 32-bits as in Visual Basic 6.0.
You can resolve this by using System.IntPtr as in Riquel's example.
Paul ~~~~ Microsoft MVP (Visual Basic) | | Paul P Clement IV Friday, October 23, 2009 5:07 PM | ok changed over those api's to integer but still no go still get these errors in my debug
GetWindowThreadProcessId Error: 0
GetWindowThreadProcessId sThread: 3500
GetWindowThreadProcessId cProcess: 5004
OpenProcess Error: 1008
OpenProcess mThread: 1560
ReadProcessMemory1 Error: 1008
CopyMemory Error: 0
ReadProcessMemory2 Error: 299
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll
CloseHandle Error: 2
i know that 1008 is a no token error but dont know how to change that and the 299 error is only copyed half the process
| | Tiger39m9 Friday, October 23, 2009 6:03 PM | ok i think i might have found out where my error is coming from is this ok now i changed over to this CopyMemory got it from pinvoke <DllImport("kernel32.dll", EntryPoint:="RtlCopyMemory")> _ Public Sub CopyMemory(ByVal Destination As IntPtr, ByVal Source As IntPtr, ByVal Length As UInteger) End Sub for this call Call CopyMemory(psnHold, ScreenName, 4) gives me this error A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll going from the way it is programmed from above is the ScreenName is a string, but in the call its a IntPtr
Screen name needs to stay a string but how would i get this to work with the new copymemory call
now i matched up both the vb6 code and the vb.net code ran them both this is what i get for vb6
using debug.print
5276 484 104589920 104589948 1 Person hold 104488176 1
now in vb.net i get this
GetWindowThreadProcessId Error: 0 GetWindowThreadProcessId sThread: 5276 GetWindowThreadProcessId cProcess: 5788 OpenProcess Error: 1008 OpenProcess mThread: 1556 104589920 104589948 ReadProcessMemory1 Error: 1008 1 A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll CopyMemory Error: 1008 Person Hold:0 ReadProcessMemory2 Error: 299 1 A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll CloseHandle Error: 2
so i beleave the problem is in the copymemory
| | Tiger39m9 Saturday, October 24, 2009 1:47 PM | ok did some more error handling now it might make more sense ok this is vb6 of the program
GetWindThreadProcessId Error: 0 GetWindowThreadProcessId sThread: 5276 GetWindowThreadProcessId cProcess: 5788 OpenProcess Error: 0 OpenProcess mThread: 1296 itmHold: 104589920 itmHold: 104589948 Read Process Memory1: 1 Person hold: 104488176 Read Process Memory2: 1 CloseHandle Error: 0
now the vb.net
GetWindowThreadProcessId Error: 0 GetWindowThreadProcessId sThread: 5276 GetWindowThreadProcessId cProcess: 5788 OpenProcess Error: 1008 this error means no token OpenProcess mThread: 1540 itmHold: 104589920 itmHold: 104589948 ReadProcessMemory1 Error: 1008 this error means no token Read Process Memory1: 1 A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll CopyMemory Error: 1008 this error means no token Person Hold: 0 ReadProcessMemory2 Error: 299 this error means partial copy Read Process Memory2: 1 A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll CloseHandle Error: 2 this error means file not found
now if i can fix these errors one at a time, i might get some where i need to fix the openprocess error first, but it deals with tokens i have not done anything with tokes before, i have read aboutit, but cant figure it out | | Tiger39m9 Saturday, October 24, 2009 3:49 PM | You can use this tool to make PInvoke easy. It will help us write correct signature. http://blogs.msdn.com/vbteam/archive/tags/PInvoke/Jared+Parsons/default.aspx Please upgrade VB6 code to VB.NET step by step. When you have the questions, discuss it with us here. Also please let us know how you use the LB_GETTEXT Message in this scenario. If in this scenario SendMessage fails, please let us know the returned value to know your scenario. http://www.xs4all.nl/~rjg70/vbapi/ref/l/lb_gettext.html
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Riquel_Dong Monday, October 26, 2009 10:06 AM | ok did as u said and this is what i come up with now
REM new pinovkes
<System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="OpenProcess")> Public Function OpenProcess(ByVal dwDesiredAccess As UInteger, <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal bInheritHandle As Boolean, ByVal dwProcessId As UInteger) As System.IntPtr End Function
<System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="CloseHandle")> Public Function CloseHandle(<System.Runtime.InteropServices.InAttribute()> ByVal hObject As System.IntPtr) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean End Function
<System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint:="ReadProcessMemory")> Public Function ReadProcessMemory(<System.Runtime.InteropServices.InAttribute()> ByVal hProcess As System.IntPtr, <System.Runtime.InteropServices.InAttribute()> ByVal lpBaseAddress As System.IntPtr, ByVal lpBuffer As System.IntPtr, ByVal nSize As UInteger, ByVal lpNumberOfBytesRead As System.IntPtr) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean End Function
<DllImport("kernel32.dll", EntryPoint:="RtlCopyMemory")> Friend Sub CopyMemory(ByVal Destination As IntPtr, ByVal Source As IntPtr, ByVal Length As UInteger) End Sub
<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SendMessageA")> Public Function SendMessageA(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal Msg As UInteger, <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.SysUInt)> ByVal wParam As UInteger, <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.SysInt)> ByVal lParam As Integer) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.SysInt)> Integer End Function
ok changed over to intptr
Public Function AddAOL8ListToList(ByVal ListToGet As Integer, ByVal ListToAddTo As ListBox, Optional ByVal AddUser As Boolean = False) On Error Resume Next
Dim cProcess As IntPtr, itmHold As IntPtr, ScreenName As IntPtr Dim psnHold As IntPtr, rBytes As IntPtr, Index As Integer Dim sThread As IntPtr, mThread As IntPtr
sThread = GetWindowThreadProcessId(ListToGet, cProcess) 'this 'OpenProcess' API Call allows for us to read the contents of the 'listbox in a nonconventional way, since conventional methods dont work :) 'We will read that tasks of the window (thread) into mThread& Debug.WriteLine("GetWindowThreadProcessId Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error) Debug.WriteLine("GetWindowThreadProcessId sThread: "(sThread)) Debug.WriteLine("GetWindowThreadProcessId cProcess: "(cProcess))
mThread = OpenProcess(PROCESS_READ Or RIGHTS_REQUIRED, False, cProcess)
'If its valid, then commence adding Debug.WriteLine("OpenProcess Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error) Debug.WriteLine("OpenProcess mThread: "(mThread))
If mThread Then 'Loop through the list items using my ListCount Procedure 'We must subtract 1 since its zero-based For Index = 0 To ListCount(ListToGet) - 1 'Get the current screen name -the invalid characters ScreenName = New String(vbNullChar, 4) 'Get's the screen name from the list through itmHold&
itmHold = SendMessage(ListToGet, LB_GETITEMDATA, CInt(Index), 0) Debug.WriteLine("itmHold: "(itmHold)) * have problem with this itmHold = itmHold + 28
Debug.WriteLine("itmHold: "(itmHold)) 'Read the data from itmHold with the ReadProcessMemory API Call, 'this will enable us to get the actual data via the "non-conventional" way :) 'heh, trying to explain as simple as possible.. basically its reading the data 'in a special way into th memory
Call ReadProcessMemory(mThread, itmHold, ScreenName, 4, rBytes) Debug.WriteLine("ReadProcessMemory1 Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error) Debug.WriteLine("Read Process Memory 1: " & ReadProcessMemory(mThread, itmHold, ScreenName, 4, rBytes))
'Now we will read that memory-added data Call CopyMemory(psnHold, ScreenName, 4) Debug.WriteLine("CopyMemory Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error)
Debug.WriteLine("Person Hold: "(psnHold)) * and this psnHold = psnHold + 6
'Subtract invalid characters ScreenName = New String(vbNullChar, 16) 'Read into memory again Call ReadProcessMemory(mThread, psnHold, ScreenName, Len(ScreenName), rBytes) Debug.WriteLine("ReadProcessMemory2 Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error) Debug.WriteLine("Read Process Memory 2: " & ReadProcessMemory(mThread, psnHold, ScreenName, Len(ScreenName), rBytes))
'Finally, we've got our SN ScreenName = Left(ScreenName, InStr(ScreenName, vbNullChar) - 1) 'Make sure, if the user doesn't want to add the actual user, then 'dont add to list, otherwise, add :) If ScreenName.ToString <> GetUser() Or AddUser = True Then ListToAddTo.Items.Add(ScreenName) End If 'Move on to next SN :) Next Index 'Close the processed memory thread Call CloseHandle(mThread) Debug.WriteLine("CloseHandle Error: " & System.Runtime.InteropServices.Marshal.GetLastWin32Error)
End If
End Function
note key * = Error1Operator '+' is not defined for types 'System.IntPtr' and 'Integer'.
this is the errors i get now
GetWindowThreadProcessId Error: 0 GetWindowThreadProcessId sThread: 5904 GetWindowThreadProcessId cProcess: 4696 OpenProcess Error: 1008 OpenProcess mThread: 1528 itmHold: 106206184 itmHold: 106206212 A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll ReadProcessMemory1 Error: 1008 A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll CopyMemory Error: 1008 Person Hold: 0 A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll ReadProcessMemory2 Error: 1008 A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll CloseHandle Error: 2
LB_ gettext dose not work on a listbox across process that dose not have and LBS_HASSTRINGS
i have tried it before on vb6 and dont work
here is vb6 to show u i have tried it
Public Const LB_GETCOUNT = &H18B Public Const LB_GETTEXT = &H189 Public Const LB_GETTEXTLEN = &H18A Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
mod
Public AOLChild As Integer Public AOLFrame As Integer Public MDIClient As Integer Public AOLList As Integer Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpszl As String, ByVal lpsz2 As String) As Integer
form
AOLFrame = FindWindow("AOL Frame25", vbNullString)
MDIClient = FindWindowEx(AOLFrame, 0, "MDIClient", vbNullString)
AOLChild = FindWindowEx(MDIClient, 0, "AOL Child", vbNullString)
AOLList = FindWindowEx(AOLChild, 0, "_AOL_Listbox", vbNullString)
Dim count As Long ' number of items in the list box Dim s2l As Long ' index of the second-to-last item Dim itemtext As String ' text of that item Dim textlen As Long ' length of the item text ' Figure out the index of the second-to-last item by subtracting two from ' the total item count (remember, the index is zero-based). count = SendMessage(AOLList, LB_GETCOUNT, ByVal CLng(0), ByVal CLng(0)) s2l = count - 0 ' Make the string long enough to receive that item's text. textlen = SendMessage(AOLList, LB_GETTEXTLEN, ByVal s2l, ByVal CLng(0)) itemtext = Space(textlen) & vbNullChar ' Get the item text and remove the trailing null. textlen = SendMessage(AOLList, LB_GETTEXT, ByVal s2l, ByVal itemtext) itemtext = Left(itemtext, textlen) ' Finally, display the result. Debug.Print "The second-to-last item is "; itemtext
itemtext comes up blank in vb6
| | Tiger39m9 Monday, October 26, 2009 1:57 PM | note key * = Error1Operator '+' is not defined for types 'System.IntPtr' and 'Integer' i fixed this problem by doing this changed back to int32 Dim psnHold As IntPtr,itmHold As IntPtr to and int32 now i get and "0" in my listbox now and with these new errors
GetWindowThreadProcessId Error: 0
OpenProcess Error: 1008
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IndexOutOfRangeException' occurred in ScreenNames1.exe
A first chance exception of type 'System.IndexOutOfRangeException' occurred in ScreenNames1.exe
ReadProcessMemory1 Error: 1008
Read Process Memory 1: False
A first chance exception of type 'System.AccessViolationException' occurred in ScreenNames1.exe
CopyMemory Error: 1008
P
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll
ReadProcessMemory2 Error: 1008
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentException' occurred in Microsoft.VisualBasic.dll
CloseHandle Error: 2
| | Tiger39m9 Monday, October 26, 2009 3:17 PM | anybody else able to help me with this problem | | Tiger39m9 Wednesday, November 04, 2009 5:13 PM | Please refer to this article about how to read another processes memory in .NET using P/Invoke and Win32 Api's. http://www.codeproject.com/KB/trace/minememoryreader.aspx You can use the following tool to get VB.NET code: http://www.developerfusion.com/tools/convert/vb-to-csharp/
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Riquel_Dong Thursday, November 05, 2009 1:32 AM | well i could not get it to work in .net like i need it been working on this problem for a long time about 4 mounths
so going to stop working on this part for now but a little good news tho
i made the program in vb6 to get the listbox items that i need, and move that text to a textbox in the same program in vb6. so now the text that i need is in a window that i can get easly.
its a round about way of doing what i need, but it works. - Marked As Answer byTiger39m9 Friday, November 06, 2009 6:44 PM
-
| | Tiger39m9 Friday, November 06, 2009 6:44 PM |
|