flat assembler
Message board for the users of flat assembler.
Index
> Windows > problems in Displaying text in a richedit |
Author |
|
mns 26 Mar 2012, 16:19
i need to find a name(string) in a file and display all the infomation(contain in the file), relevent to the name, in a richedit control and if multiple instances of the name
found,informations of each instance must be displayed. i tried with following(files are attached with this)But windows given a error!! please help!!!!!
|
|||||||||||
26 Mar 2012, 16:19 |
|
mns 27 Mar 2012, 12:06
Thank you very much gunblade.
I learnd lot from your response,and changed the code accordingly. BUT to accomplish my goal what can I do? If I remove the methode, Reading the file and allocating desired part of the file to the variable(using CreateFile and ReadFile) in ..search part ,there should be another methode to do that.(please someone tell me if there is) and why windows giving error msg. Please someone help |
|||
27 Mar 2012, 12:06 |
|
mns 27 Mar 2012, 16:03
Ok, I changed the code like below(attached with this).But still windows gives a error.Can someone explain whay???
|
|||||||||||
27 Mar 2012, 16:03 |
|
Picnic 27 Mar 2012, 18:53
msvcrt function calls (strlen, strncpy, e.t.c) needs cinvoke.
Focus on your .NEXT subroutine, do some tests. e.g try to add each record separately. |
|||
27 Mar 2012, 18:53 |
|
mns 28 Mar 2012, 11:01
Thanx Picnic,
But please can you explain what you mean by 'e.g try to add each record separately. ' Can anyone explain why windows giving error msg when there is a loop in that position(.NEXT subroutine) |
|||
28 Mar 2012, 11:01 |
|
Picnic 28 Mar 2012, 12:41
mns wrote: Thanx Picnic, You're welcome mns. Well, i saw that you are looping and using strstr function to search for strings and distinguish entries in hidden edx file. Remove temporary the line 'jmp .. search', notice that you can now add 2 entries by pressing next button. Also notice that if you modify the third record's Name field as 'amila', you can add 3 consecutive entries by pressing next, before crash. These are few quick observations, maybe are useful, maybe not. Re-check your code step by step, watch values. |
|||
28 Mar 2012, 12:41 |
|
gunblade 30 Mar 2012, 11:06
If you dont already - I would recommend using OllyDbg (or similar.. but i find this works best for 32-bit debugging in windows) to "step through" your program, and as Picnic says, watch the variables. Thats how I started debugging your code, however there was too many errors in order to continue nicely..
I may give it another shot with your updated code. I think when you're faced with a problem where theres soo many errors, you're better off taking out some of the code, try it with less code, see how that works, then put the other stuff back in gradually and see what causes it to break. Will let you know if i get anywhere with it, but as I say.. its been a while since I hit up the winapi properly.. |
|||
30 Mar 2012, 11:06 |
|
mns 30 Mar 2012, 12:42
thanx Picnic & gunblade,I'm in the process of what you have suggested but still no luck.And I never used a debugger before although having copies of several debuggers.
When started with less code and adding other instructions gradually,I think I found where the problem is.at the jmp instruction .which arise when loop goes more than 2 times.and I wondered problem arise due to the inadequate buffer size(data3-which i used to copy the string)i used malloc and alloc fuction to allocate a new memmory when using loop every time .But the result is the same error. |
|||
30 Mar 2012, 12:42 |
|
gunblade 30 Mar 2012, 14:24
Right, I think I have it working. It depends on the kind of behaviour you want, but it no longer crashes..
The code should look like: Code: .NEXT : mov [data3],0 ..search: cinvoke strstr,[dwBuffer],name2 cmp eax,0 je ..ending mov [data1],eax cinvoke strstr,[data1],Sname cmp eax, 0 je ..ending mov [data2],eax sub eax,[data1] add eax,146 mov [nn2],eax sub [data1],146 ;invoke ReadFile,[data1],[dwBuffer2],[nn2],dwWritten,0 cinvoke strncpy,data3,[data1],[nn2] invoke GetWindowTextLength,[hwndRichEdit] invoke SendMessage,[hwndRichEdit], EM_SETSEL,eax,eax invoke SendMessage,[hwndRichEdit],EM_REPLACESEL , FALSE ,data3 mov eax,[data2] mov [dwBuffer],eax jmp ..search ..ending: Basically: Change the invokes to cinvoke (not critical, but you waste stack by not cleaning it up yourself if you dont use cinvoke). and (importantly) add that cmp eax, 0/je ..ending after the second strstr. What was happening was that you were fnding all the results, but when you got to the end, you ended up getting a NULL back from that second strstr (since it cant find the next ==== delimiter), and then everything after that (strncpy/etc) would fail.. because your [nn2] "count" would be some random garbage number. So yeah.. the current behaviour is that it results ALL search results in one page. So.. you run the program, you hit next and it brings up that white window, then you hit next, and it shows you all the results in one page (scroll down and you'll see that it includes both the 2 and 3 year old amila). You can then keep hitting next, but it will keep showing the same results.. If you were wanting instead to have one patient record per page.. (so, first time you hit next, it shows the first record, between the == and ==, the second time, it shows the second record, and then stops after that..) then you'll need to stop after the first succesfull strstr for the name that you're searching for, do the sendmessage to window, then when you hit next, you do the same again, if that is the behaviour you want, then let me know, it should be an easy change.. |
|||
30 Mar 2012, 14:24 |
|
mns 30 Mar 2012, 17:21
Thank you very much gunblade solving this headache for me.
Actually this is a part of a programme(for learning perposes of win32 assembly) that I am making which help to save the details of a patient in a file(each for a day)and can recover the details of a patient when ever needed.For the time being your first solution is more than enough.Thanx again. |
|||
30 Mar 2012, 17:21 |
|
gunblade 31 Mar 2012, 00:52
No problem. As i say, if you want to solve issues like this in the future, a debugger like OllyDbg is vital.. You first run the program through the debugger, and see where it crashes, what instruction it was on, and what it was (a write to memory, a read from memory, a bad instruction?), then from there you can set breakpoints and trace the execution as it goes..
The other way, is to add "debug" lines in your code, where you print out the current status at some points.. easiest if you make it a small macro or similar that pops up a messagebox with current status and any registers you're wanting to watch.. although this means modifying the code, which could mess with any existing errors (or cause more), hence why the debugger is preferred. Good luck with it, let us know if any more issues come up.. |
|||
31 Mar 2012, 00:52 |
|
AsmGuru62 31 Mar 2012, 11:40
In addition, the 'debugging' printout code can be included into conditional compilation clause(s),
so you can include it or exclude with just changing a value in just one line: Code: DBG_PRINT = 1 ; <-- put this at the top of the main source ... if DBG_PRINT = 1 stdcall PrintReg32, ecx end if ... if DBG_PRINT = 1 stdcall PrintMem8, esi, 64 stdcall PrintMem32, edi, 4 end if Now, to switch off the printouts all you need to do is go to the top of the source and set that DBG_PRINT value to zero and re-assemble. |
|||
31 Mar 2012, 11:40 |
|
mns 01 Apr 2012, 15:54
Thax gunblade and AsmGuru62,for your kind suggestions.I've never thought debugging is so important in programming.And now I know it is a art must learn.
|
|||
01 Apr 2012, 15:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.