- This topic has 142 replies, 8 voices, and was last updated 10 years ago by Admin.
-
AuthorPosts
-
July 17, 2013 at 3:47 pm #186092ChikeMember
@autopilot wrote:
As long as you are not trying to use the return value in any way, the warning can be ignored without causing any crash issues.
Warnings must never be ignored,, every warning is a bug that will show up at some point. You are going to have bugs without warnings, don’t ignore bugs that are already there.
If you are not using the return value make it a sub not a function.
Warnings are logic errors that do not prevent the IDE from creating the applications but they are still errors.July 17, 2013 at 10:21 pm #186091cyberpunkMemberDeparture,
I am pretty positive I am freeing it up, I have the same basic code Autopilot uses at the end of his, all I really did was edit it to get the status value. Let me keep plugging away at it and see how much further I can get, I was mainly looking to narrow down the possible reasons so I don’t go off in the wrong direction. I’m only reading data so it really is odd that it is crashing Paltalk at all. Departure, I really do appreciate your thoughts though.Chike,
I am inclined to agree with Autopilot in this case because I really am using the function more like a Sub anyway, it directly sets the value of a Textbox rather than passing the value back. However Chike, I think you are right about eliminating things that you can eliminate. No need to willfully introduce errors. I have corrected that issue so no more warnings, but I doubt that’s crashing paltalk and the timer works fine.
I think I’ll add another LVITEM structure for the UserName calls other than the one I’m using for the UserStatus calls . I’ve also combed through the code and eliminated a couple extra checks. Going to institute some sort of process that only checks once every 5 or 10 seconds when no one is one mic. Let me see where I stand after all that. I do appreciate all the input though. I recognize all of you from my forum reading lol.Thanks again all of you.
July 18, 2013 at 12:31 am #186090ChikeMemberLOL you are just going to wait longer for crashes.
You realy want to check as many times as possible and make it crush quckly, for testing only of course.If the Textbox is part of the class the Callback is and the callback is not shared, that’s ok.
Rule #2: do not use global varibles.What reason you have to use different structure for LVITEM?
July 18, 2013 at 12:46 am #186089cyberpunkMemberI was thinking that each LVITEM structure might be it’s own chunk of memory. I was grasping at straws and i think might have shown how funny noobs can be with their odd assumptions! lol I had also thought it was just the structure that the chunk of memory would be using as well, but as i said I was grasping at straws and admittedly still piecing it all together. Clearly, I have a long way yet to go, but damn I am having fun!
I understand what you are saying and perhaps you are right, maybe i need to think the other way and see what it is i adjust that is doing the crashing. When I was using my first attempt at making this I was able to crash Paltalk within 15 minutes, but I had one timer accidently set to check 10 times a second lol.
Thanks for the idea Chike.
July 18, 2013 at 1:10 am #186088ChikeMemberFirst and before all, with what error does paltalk crash?
It’s easy to see if it’s releasing memory problem, just monitor it with task manager.July 18, 2013 at 2:06 am #186087cyberpunkMemberDamn noobs lol. I should have thought of that. Working on crashing it now, but without tweaks, just curious how long it goes is all. I will get back when I have more information.
July 19, 2013 at 9:06 pm #186086cyberpunkMemberSo, it definitely seems to be a memory issue, and yes Departure, I will post the code 😀 for the function that I use for getting the user names. I turned off the Status checks and it still crashes Paltalk. I thought the last few lines before the Return statement freed up the memory. Let me know if you need to see the code to the button that feeds the Index position to this function.
The only information I could gain from the Event logs pointed to palsound.dll (odd), all windows offered after the crash was to update Paltalk with no other information on what caused the crashed. I notice the crash before it happens, My app stops getting username and status updates but I still have sound and text for about five minutes, the NicList even appears to be working, then Paltalk suddenly closes. The memory usage value varies within 250 – 300 MBs (just over twice what Paltalk loads up at. I seem to be eating memory at a rate of 2MBs/3minutes. During this time there are memory releases but probably from the chat text log buffer.
Public Function GetUserName(ByVal lstviewhwnd As IntPtr, ByVal itemIn As Integer) As String
Dim UserName As String
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 index As Integer
Dim tmpString As String = String.Empty
Dim ProcessID As Integer
Dim ItemCount As Integer
Dim i As Short
ItemCount = SendMessage(lstviewhwnd, LVM_GETITEMCOUNT, 0, 0)
'**********************
'init the string buffer
'**********************
ReDim strBuffer(StringBufferLength)
'***********************************************************
'open a handle to the process and allocate the string buffer
'***********************************************************
Call GetWindowThreadProcessId(lstviewhwnd, ProcessID)
pHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 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 = 0
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)
'*************************************************************
'*************************************************************
'*************************************************************
i = itemIn
'*************************************************************
'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)
'*************************************************************
For index = LBound(strBuffer) To UBound(strBuffer)
If Chr(strBuffer(index)) = vbNullChar Then Exit For
tmpString = tmpString & Chr(strBuffer(index))
Next index
tmpString = Trim(tmpString)
UserName = tmpString 'added in pititful attempt to turn it into a function
Form1.TextBox200.Text = tmpString 'This is all i had it doing initally without a return
tmpString = String.Empty 'added in pititful attempt to turn it into a function
'**************************************************
'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)
Return UserName 'added in pititful attempt to turn it into a function
End FunctionJuly 19, 2013 at 10:21 pm #186085ChikeMemberIt’s not clear from documentation what happen if you commit without reseve, but you should call VirtualAlloEx with MEM_COMMIT or MEM_RESERVE
Would also help of you publish LVITEM structure decleration.
July 20, 2013 at 12:55 am #186084cyberpunkMemberConst StringBufferLength As Integer = 255
Const LVM_FIRST As Integer = &H1000
Const LVM_GETITEMCOUNT As Integer = (LVM_FIRST + 4)
Const LVM_GETNEXTITEM As Integer = (LVM_FIRST + 12)
Const LVM_FINDITEM As Long = (LVM_FIRST + 13)
Const LVM_SETITEMPOSITION As Integer = (LVM_FIRST + 15)
Const LVM_GETITEMPOSITION As Integer = (LVM_FIRST + 16)
Const LVM_GETITEMTEXT As Integer = (LVM_FIRST + 45)
Const LVM_SORTITEMS As Integer = (LVM_FIRST + 48)
Const LVM_GETSELECTEDCOUNT As Integer = (LVM_FIRST + 50)
Const LVM_GETITEM As Integer = (LVM_FIRST + 75)
Const LVNI_SELECTED As Integer = &H2
Const LVFI_PARAM As Integer = &H1
Const LVIF_TEXT As Integer = &H1
Const LVIF_IMAGE As Integer = &H2
Const LVM_FINDITEMW As Integer = (LVM_FIRST + 83)
Const LVIS_SELECTED As Integer = &H2
Const LVIF_STATE As Integer = &H8
Const LVM_SETITEMSTATE As Integer = (LVM_FIRST + 43)
Const PROCESS_VM_OPERATION As Integer = &H8S
Const PROCESS_VM_READ As Integer = &H10S
Const PROCESS_VM_WRITE As Integer = &H20S
Const MEM_COMMIT As Integer = &H1000S
Const PAGE_READWRITE As Integer = &H4S
Const MEM_RELEASE As Integer = &H8000S
Const MEM_RESERVE As Integer = &H2000S
Structure LV_ITEMA
Dim mask As Integer
Dim iItem As Integer
Dim iSubItem As Integer
Dim state As Integer
Dim stateMask As Integer
Dim pszText As Integer
Dim cchTextMax As Integer
Dim iImage As Integer
Dim lParam As Integer
Dim iIndent As Integer
End StructureJuly 20, 2013 at 3:34 am #186083DepartureMemberIf it becomes too much problems use UIAutomations then you dont need to deal with any of this..
July 20, 2013 at 8:58 pm #186082cyberpunkMemberDeparture,
I was hoping to get your take on the function. Do you see why I felt I was releasing the memory, though clearly even I could tell it looked like a memory issue, but I just felt like that code at the end was releasing it. I should have thought to use Task manager well before Chike suggested it, but it is clearly only eating memory when I hit the NicList. I would appreciate any thoughts on why this function doesn’t appear to be releasing memory.I took a look at your post, and I think for now UIAutomation is out of my league. But I do plan on trying to work with it since you seem convinced that using it will help with the Paltalk updates breaking code. But I put together what I have by hacking other things and then making it do what I wanted, I can’t do that with this framework yet because there are not enough examples of what I can do with it. Remember, not only am I a noob but I am teaching myself so I am working with a dirt foundation. I am not ruling out UIAutomation, but not sure I can do anything with it at this point.
While I was perusing Auto-Pilot’s forums, I also read that the method I am using to read the NicList does seem to eventually crash Paltalk, some guy had an even more simple app that read the first username in the NicList every 8 seconds and it crashed Paltalk within a day. Not sure if UIAutomation would still need to hook into the process itself to get the data from the listview. If it can read the list like SysExporter can than I think you are 100% right and this is the way to go, but SysExporter could not get the item.iImage, will be waiting to here if UIAutomation can get the item.Image value.
For now, I am still enjoying working on the features for the timer, this programming stuff sure is addictive, I can’t tell you how many nights I look at the clock and it is already 3AM and I am still looking at the PC! 😀
July 20, 2013 at 11:04 pm #186081cyberpunkMemberDeparture,
I took an even closer look at your demo code after getting a really general overview of UIAutomation, and correct me if I am wrong, but your demo appears to be getting both the username and the status subitems, is that true? I am assuming the 1 and 2 in your final Write statement is getting both values, would like to know if you are successful in that. It is an interesting approach Departure.
This might help me with the next app I want to make….a fantasy football app (That’s Yankee football not Aussie football lol) This technique might make working with a browser to get team/player stats a lot easier. Am really now very curious about this library, but I biting off more than I can chew, but we’ll see how long I can chew.
July 21, 2013 at 5:48 am #186080ChikeMemberDon’t be looking for the easy way out and replace the code instead of debugging it.
I already know what your problem is, and if it is the ecact same others use they have the same problem too.
Since you already know where the problem is it should not be difficult.
I’ll hint you though, and the hint is related to our previous discussion about ignorring warnings and definition of a routine as sub or function.
Yes I am not making your life easy, it’s not that obviouse of a hint, think.
But not to make your life too difficult I’ll hint you again, you can find the bug in a single debug walk on the code as posted.July 21, 2013 at 5:52 am #186079DepartureMemberlol chike you got in just before me, I was going to suggest to him to set break point and look at variables while stepping through the code, Also look to make sure your not exiting the function before releasing the memory you created at the start of the function
July 22, 2013 at 12:57 am #186078cyberpunkMemberChike,
I would rather learn than have you solve it for me anyway, but I might need better hints lol!
I totally turned this code into a sub now to rule out my inexperience with how functions function as the culprit. I also noted Departure’s advice about breakpoints. Now, I have seen that advice throughout the forums and even tried it once and was left scratching my head as to what good that was……until I decided to google debugging tips on VS2010 and realized that breakpoints is just the beginning, I had expected when i stepped through to see the variable information in the Output window or Immediate Window, had no idea you could hover over the variables and see the values and even pin them so no need to hover! Then I googled some more and learned there are conditional breakpoints and trace points and now I am getting a better idea of the tools of the trade for debugging. I figure I am still missing some pieces in the debugging process and obviously lacking experience in using the tools and deciphering it all.I point this all out, partly to reiterate how much of a noob I am so you guys remember that when giving hints, but I also point this out because I want you to see that I am willing to research things on my own, but do need these nudges and I am glad you guys are willing to entertain my ignorance….then again, maybe my ignorance is entertaining you! lol
So this is where I stand now, i have added the code to the button click event that was used to feed the index position value and removed the Return statements. The Timer program still functions as it did, fortunately and unfortunately it still has the same issue. The only other warning I have is that GetwHndByClassNameByPartialCap is not returning a value on all codepaths but that warning has been with this AdminBot code since I first started playing with it and this issue only started with the Timer code i have added.
When I was playing around with the newly discovered debugging tools, I saw the result variable was 1 all the way through the codewalk until the CloseHandle statement when it went 0, my gut tells me that is a good thing, but my head tells me that 0 could mean false and might be an error. Then it occurred to me, what is this result variable used for? My desire to see how things work I removed the “result = ” from those lines of code that had it in my sub and noticed it still worked just fine. I figure they are there for a reason, but for the life of me, I can’t figure out what this result variable is all about. Screwing around with the code is how I have put together what I have so far, I realize this is not the best method, but it is what it is.
-
AuthorPosts
Related
- You must be logged in to reply to this topic.