cs_xtravagon
Messages postés4Date d'inscriptionjeudi 4 novembre 2004StatutMembreDernière intervention17 octobre 2009
-
15 oct. 2009 à 02:10
cs_xtravagon
Messages postés4Date d'inscriptionjeudi 4 novembre 2004StatutMembreDernière intervention17 octobre 2009
-
17 oct. 2009 à 00:05
Salut tt le monde
je suis débutant en programmation , j'essaye de faire un programme qui récupère le contenu d'une listeview d'un autre programme avec api,
le petit programme fonction mais le problème c'est que a certain tempe, le programme contenons la listview se bloc.
voila mon programme:
je croix que le problème viens du conflit dans la zone mémoire
merci de m'aider
'******************** Get all Item string by giving the list view handl ****************************
Public Function GetItemList(ByVal lstviewhwnd As Integer) As Array
Dim result As Integer
Dim myItem As LV_ITEMA
Dim pHandle As Integer
Dim pStrBufferMemory As Integer
Dim pMyItemMemory As Integer
Dim strBuffer() As Byte
Dim strBuffer2() As Byte
Dim index As Integer
Dim tmpString As String = String.Empty
Dim ProcessID As Integer
Dim ItemCount As Integer
Dim i As Short
Dim ItemsList() As String
' Create two different encodings.
Dim ascii As Encoding = Encoding.ASCII
Dim [unicode] As Encoding = Encoding.Default
ItemCount = SendMessage(lstviewhwnd, LVM_GETITEMCOUNT, 0, 0)
ReDim ItemsList(ItemCount)
'**********************
'init the string buffer
'**********************
'***********************************************************
'open a handle to the process and allocate the string buffer
'***********************************************************
Call GetWindowThreadProcessId(lstviewhwnd, ProcessID)
pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_WRITE Or PROCESS_VM_READ, False, ProcessID)
pStrBufferMemory = VirtualAllocEx(pHandle, 0, StringBufferLength, MEM_COMMIT, PAGE_READWRITE)
'************************************************************************************
'initialize the local LV_ITEM structure
'The myItem.iSubItem member is set to the index of the column that is being retrieved
'************************************************************************************
myItem.mask = LVIF_TEXT
myItem.iSubItem = 2
myItem.pszText = pStrBufferMemory
myItem.cchTextMax = StringBufferLength
'**********************************************************
'write the structure into the remote process's memory space
'**********************************************************
pMyItemMemory = VirtualAllocEx(pHandle, 0, Len(myItem), MEM_COMMIT, PAGE_READWRITE)
result = WriteProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
'*************************************************************
'*************************************************************
'*************************************************************
For i = 0 To ItemCount - 1
ReDim strBuffer(StringBufferLength)
ReDim strBuffer2(StringBufferLength)
'*************************************************************
'send the get the item message and write back the memory space
'*************************************************************
result = SendMessage(lstviewhwnd, LVM_GETITEMTEXT, i, pMyItemMemory)
result = ReadProcessMemory(pHandle, pStrBufferMemory, strBuffer(0), StringBufferLength, 0)
result = ReadProcessMemory(pHandle, pMyItemMemory, myItem, Len(myItem), 0)
'**************************************************
'turn the byte array into a string and send it back
'**************************************************
For index = LBound(strBuffer) To UBound(strBuffer)
If Chr(strBuffer(index)) = vbNullChar Then Exit For
strBuffer2(index) = strBuffer(index)
Next
tmpString = [unicode].GetString(strBuffer2).Trim(Chr(0))
ItemsList(i) = tmpString
tmpString = String.Empty
strBuffer = Nothing
strBuffer2 = Nothing
Next
'**************************************************
'deallocate the memory and close the process handle
'**************************************************
result = VirtualFreeEx(pHandle, pStrBufferMemory, 0, MEM_RELEASE)
result = VirtualFreeEx(pHandle, pMyItemMemory, 0, MEM_RELEASE)
result = CloseHandle(pHandle)
result = Nothing
Return ItemsList
End Function