flat assembler
Message board for the users of flat assembler.

Index > Windows > DLL Trouble

Author
Thread Post new topic Reply to topic
Jesse Redick



Joined: 11 Jan 2011
Posts: 15
Jesse Redick
Hello once again FASM experts,

I am here yet again with another problem. This time i'm trying to figure out DLL's and i'm having a bit of trouble with my example. It seems to compile fine and so does the app I create with it. The problem is, once I run my app, Notepad does pop up, but so does a Microsoft error asking me if I want to report my error. What could be the problem? Here is is my DLL and App in full:

ShellX.dll:

Code:
format pe gui DLL
entry DllMain

include 'win32a.inc'

section '.data' data readable writeable

a db 'notepad',0

section '.code' code readable executable

proc DllMain,hinstDll,fdwReason,lpvReserved
mov  eax,1
ret

Shell:
invoke ShellExecute,0,0,a,0,0,5
[color=red]ret[/color]
endp

section '.idata' import data readable

library shell32,'shell32.dll'

import shell32,ShellExecute,'ShellExecuteA'

section '.edata' export data readable

export 'ShellX',Shell,'Shell'

section '.reloc' fixups data discardable    


Notepad.asm

Code:
format pe gui
entry Test

include 'win32ax.inc'

section '.code' code import writeable readable executable

library ShellX,'ShellX.dll'

import ShellX,Shell,'Shell'

Test:
invoke Shell
ret    


EDIT: Nevermind. I have it fixed. I forgot to put "ret" under "Shell:".
Post 25 Jan 2011, 19:00
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
You do not return from your Shell procedure (and also you put it inside the "proc"-"endp" boundaries defined for DllMain, which is not a good idea). After I change it to:
Code:
proc DllMain,hinstDll,fdwReason,lpvReserved 
mov  eax,1 
ret
endp

Shell: 
invoke ShellExecute,0,0,a,0,0,5 
retn     
it works OK. Though I needed to call the program source with some other name than "notepad.asm" (I used "n.asm") - if it is named "notepad" then it ends up executing itself in a crazy loop.
Post 25 Jan 2011, 19:10
View user's profile Send private message Visit poster's website Reply with quote
Jesse Redick



Joined: 11 Jan 2011
Posts: 15
Jesse Redick
Thanks for the tips Tomasz. I'm still learning. Smile
Post 26 Jan 2011, 02:27
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.