minor28,

Yes! That is the problem! You can run your code on your machine, and it will work! But on another machine it crashes! If you just intend for the code to run on your machine, fine. But if you intend for others to use your tool, keep in mind you might have a problem with LARGE LOCAL DECLARATIONS!

The problem probably is the size of your LOCAL's. I've been trying to convince you of that, and thought I might have proved it to you with my last post.

A simple test:

Add the few lines of code--the ones between the two comment lines--recompile, and submit for KetilO to try.

That's it for me.

I hope I've helped a little. Please excuse my strong language above. :oops:

farrier
:oops:
Posted on 2004-09-28 07:36:56 by farrier
Touching the stack frame can be done as easy as this:



mov eax,ebp
.while eax>esp
mov dword ptr [eax],0
sub eax,4096
.endw


KetilO
Posted on 2004-09-28 09:23:19 by KetilO
farrier,

I hope you will overlook my ignorance, but you have convinced me. My intention was to follow KetiO's advice because I couldn't get the program to work with the touching. Here is the process of the main dialog.

MainDlgProc proc uses edx edi esi hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

LOCAL buffer[4096]:byte
LOCAL buffer2[256]:byte
LOCAL buffer3[256]:byte
LOCAL printout[4096]:byte

LOCAL pos:dword
LOCAL hdi:HD_ITEM

;Touching the stack frame
mov eax,ebp
.while eax>esp
mov dword ptr [eax],0
sub eax,4
.endw

;_try
push lbl_finally ;address of safe place after guarded code
push ebp ;stack frame
push esp
assume fs:nothing
push offset ED_31 ;address of frame-based exception director
push fs:[0];address of next error structure
mov fs:[0], esp ;save the error address


.if uMsg==WM_INITDIALOG
push hWin
pop hMainDlg


The code above works on my XP. My win2k only shows the controls of the dialog.

1) If I comment the "touching the stack frame" part it still works on my XP and no change on win2k.

2) If I comment the "_try/_finally" part it still works on my XP and no change on win2k.

3) If I comment both "touching the stack frame" and "_try/_finally" it still works on my XP and now it also works on my win2k.

I don't know what touching means. For me it only put zeros in the range of the stack. If I don't put the zeros I have a lot of garbage.

I attach the last alternative. If it works at startup it will probably crach later as I have more dialogs with local buffers.
Posted on 2004-09-28 11:26:32 by minor28
Hi minor28

The idea is to touch the stack before it is used. 'uses edx esi edi' violates this.
Change your proc to:



MainDlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lPar am:LPARAM
LOCAL buffer[4096]:byte
LOCAL buffer2[256]:byte
LOCAL buffer3[256]:byte
LOCAL printout[4096]:byte

LOCAL pos:dword
LOCAL hdi:HD_ITEM

;Touching the stack frame
mov eax,ebp
.while eax>esp
mov dword ptr [eax],0
sub eax,4
.endw
push edx
push esi
push edi


remember to pop registers before ret.

KetilO
Posted on 2004-09-28 13:38:27 by KetilO
I must point out that there is no crash on my win2k. The dialog window don't show up only the buttons and statusbar. The close button (the only enabled button) closes the dialog.

I changed the uses to push/pop. No change on neither XP nor win2k. I attach the ComTool.dll.

If I remove the SEH then the win2k also works. I attach ComTool_2.dll.
Posted on 2004-09-28 15:37:25 by minor28
I must point out that there is no crash on my win2k.

If I may add my two cents...

...that's like saying your program has no bugs because you managed to get a successful run. ;)

The side effects of stack overflows are almost random by nature, and some systems are more vulnerable to them than others. I bet 2K and XP have a larger zone of guard pages :?: but on 95, 98, ME and NT it was only 4096 bytes, so when you allocate locals over that size you MUST probe the stack first.

This is not a crazy idea of farrier and Ketil :-D -- try writing a C function with over 4k of local data and disassemble, you'll see the stack probing code inserted by the compiler.

AFAIK this only holds true for Windows. I have no idea how Linux implements stacks.

Hope that helps! :)
Posted on 2004-09-28 16:51:21 by QvasiModo
Originally posted by QvasiModo:
...that's like saying your program has no bugs because you managed to get a successful run.


No, that's not what I am saying. I say because of the fact that my program works on my computer it is difficult to trace the bug. I take farrier's and Ketil's point outs seriously. If the readers get any other understanding of what I am writing it is because of my bad english.

The only sign of bug I can see is the unvisible dialog window. So far the only way I can make it visible is when I remove the exception handling. I need your help to test it in order to make my program free of bugs. Of cause I can't demand your help but if you consider my tool interesting and useful I would be very glad.

I do hope that this post don't cause any misunderst?ndings.

Best regards
Posted on 2004-09-29 00:45:51 by minor28
Hi minor28

Great!
Now it works well on my Win XP. I will try it on my Win 98SE when I get home from work.
Is there any difference in the Colref_2 you included and the Colref included in RadASM?

KetilO
Posted on 2004-09-29 03:11:45 by KetilO
Colref_2 is the same as Colref. It was a mistake it should have been ComTool_2. Glad it works but I have to change touching stack frame on a couple of more processes before it works all over. I'll do it tonight.
Posted on 2004-09-29 03:41:18 by minor28
minor28,

Glad it works


I'm glad also :)

I knew there would be a clever way of calculating the size_of_locals; Don't calculate it at all, as with KetilO's code!

   mov eax,ebp

.while eax>esp
mov dword ptr [eax],0
sub eax,4096
.endw


Very nice! Why couldn't this be part of the standard Epilogue code?

farrier
Posted on 2004-09-29 15:58:18 by farrier
I tested on a fourth computer with win98. Crash. I attach a very reduced version of the addin. Only the menuitem "Search Lib/List all libs" works. Now it is more easy to get a hang of the code. Locals 2230h bytes, touching the stack and exception handling.

I would very much appreciate if somebody can enlighten me what's wrong.

Regards
Posted on 2004-09-30 10:05:04 by minor28
Hi

Found the following:



MainDlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL buffer[4096]:byte
LOCAL buffer2[256]:byte
LOCAL buffer3[256]:byte
LOCAL printout[4096]:byte

LOCAL pos:dword
LOCAL hdi:HD_ITEM

;Touching the stack frame
mov eax,ebp
.while eax>esp
sub eax,4
mov dword ptr [eax],0
.endw
;_try
push lbl_finally ;address of safe place after guarded code
push ebp ;stack frame
push esp
assume fs:nothing
push offset ED_31 ;address of frame-based exception director
push fs:[0];address of next error structure
mov fs:[0], esp ;save the error address

push edx
push esi
push edi


And:



lbl_finally:
pop edi
pop esi
pop edx
;_finally
assume fs:nothing
pop fs:[0] ;restore next error structure
add esp, 4 ;adjust stack

ret

MainDlgProc endp



If you correct this it works on my Win98 SE

KetilO
Posted on 2004-09-30 15:10:20 by KetilO
Yes, now it works on XP, win2k and win98. Thanks, I will set all code right and come back with a new version. I have learnt pushing register after the _try code. I didn't know.

Best regards
Posted on 2004-09-30 16:06:11 by minor28
Thanks farrier and KetilO,

I hope this version will work. The VBbrowser is not completed, but I don't know if it is needed. Setting Quick search by right clicking on a library. Excel demo and tutorial in my first post.

My opinion is that this tool makes automation coding much easier. Hope you find it helpful too.

Best regards
Posted on 2004-09-30 17:03:13 by minor28
Works fine on XP. I will try it at home where I have various operating systems.
Posted on 2004-10-06 13:07:59 by Gandolf
I discovered I forgott to add "GUID" to the IID strings to be pasted to the data section.
IID__Application GUID {0000208D5h,00000h,00000h,{0C0h,000h,000h,000h,000h,000h,000h,046h}}


A new attachment.
Posted on 2004-10-06 16:56:56 by minor28
I am interested to hear if someone has tested the tool yet. For example i have assumed that it will work with lcid value equal to zero. But I don't know. Perhaps I'd better complete the tool with code for putting lcid equal to LOCALE_SYSTEM_DEFAULT. Any comments would be appraciated.
Posted on 2004-10-13 16:07:16 by minor28
I have made some minor changes.
Posted on 2004-11-16 13:44:19 by minor28