flat assembler
Message board for the users of flat assembler.

Index > Windows > About creating a DLL

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
znatz



Joined: 08 Jul 2012
Posts: 13
Location: 日本
znatz 08 Jul 2012, 05:01
I am currently learning how to create and use a DLL.

I compiled the example in the \fasmw17002\EXAMPLES\DLL directory.

It succeed but an error message, cant find the specified module shows up when I execute the output .exe file.

Is there a problem with my OS ?

Or actually what I want is an example showing the skeleton of creating a dll in fasm .

Would anyone please offer some help? Thank you.
Post 08 Jul 2012, 05:01
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 08 Jul 2012, 05:12
You should compile both "ERRORMSG.asm" and "LASTERR.asm".
After the compilation, there must be two files: "LASTERR.exe" and "ERRORMSG.dll"
Post 08 Jul 2012, 05:12
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
znatz



Joined: 08 Jul 2012
Posts: 13
Location: 日本
znatz 08 Jul 2012, 06:09
Thank you and yes, I did compile both files but it didn`t work.

Also the directory also contains the original LASTER.exe and ERRORMSG.dll files which are included after installation,
but it shows the same message when I execute the LASTER.exe file.
Post 08 Jul 2012, 06:09
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 08 Jul 2012, 07:08
Very strange. What OS?
Post 08 Jul 2012, 07:08
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
znatz



Joined: 08 Jul 2012
Posts: 13
Location: 日本
znatz 08 Jul 2012, 07:18
I tried it in 2 PCs, neither of them work.
One with Windows 7 32bit ultimate. When I run it as administrator, it tells me access denied.
Another one with windows xp professional. When run, it tells me specific module is missing.
Post 08 Jul 2012, 07:18
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 08 Jul 2012, 07:33
Can you post a screenshot? Actually the proper work of this example is to show error message box. Try to modify the example to show something else, in order to exclude false impression.
Post 08 Jul 2012, 07:33
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 08 Jul 2012, 07:49
lol. what an oxymoron. Last error being "module not found"
Post 08 Jul 2012, 07:49
View user's profile Send private message Reply with quote
znatz



Joined: 08 Jul 2012
Posts: 13
Location: 日本
znatz 08 Jul 2012, 07:59
Thank you for your advice!!
I changed the MB_OK to MB_OKCANCELand it shows different button in it.

Terribly sorry for my ignorance.

I missed the ShowLastError part and kept thinking of a system error because the msg changed in different system...
Post 08 Jul 2012, 07:59
View user's profile Send private message AIM Address Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 08 Jul 2012, 08:09
typedef wrote:
lol. what an oxymoron. Last error being "module not found"
cool Surprised this is but normally applied to poetry. i dont know if there is a terminology for those frequent cases by programming.
btw are you interested in languages and poetry ?
Cheers,

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 08 Jul 2012, 08:09
View user's profile Send private message Visit poster's website Reply with quote
znatz



Joined: 08 Jul 2012
Posts: 13
Location: 日本
znatz 08 Jul 2012, 10:06
Yeah, that message made me crazy. Thank you all guys.

And another headache comes out now when I am writing my first dll. Not actually mine, I just rewrite part of the code in the ERRORMSG.asm to make it mine.
However, it kept telling me the mydll.dll is not a valid image file when I call the function in it from another file.

Did I miss something again?


Description:
Download
Filename: mydll.ASM
Filesize: 476 Bytes
Downloaded: 420 Time(s)

Post 08 Jul 2012, 10:06
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 08 Jul 2012, 10:34
There was some problem with dll's that has no import section. Try to import some functions at least from kernel32.dll
Post 08 Jul 2012, 10:34
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 08 Jul 2012, 10:40
for any reasons i didnt investigate, .reloc should preceed export.
try this
Code:
section '.reloc' data readable discardable fixups
section '.edata' export data readable
;--- follow export
    
Cheers,

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 08 Jul 2012, 10:40
View user's profile Send private message Visit poster's website Reply with quote
znatz



Joined: 08 Jul 2012
Posts: 13
Location: 日本
znatz 08 Jul 2012, 10:41
After I post the last message, I import kernel32.dll and called ExitProcess once in DLLEntryPoint then it works!
And now comes the problem, I dont see anything likely in ERRORMSG.asm.
Does it mean the ERRORMSG did the same thing implicitly/indirectly (invoke ExitProcess) ?
Post 08 Jul 2012, 10:41
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 08 Jul 2012, 10:53
You don't have to call ExitProcess. Only the import section must exists and be not empty.
ERRORMSG.asm imports some API functions and this is enough for Windows to accept it as a valid .dll
Post 08 Jul 2012, 10:53
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
znatz



Joined: 08 Jul 2012
Posts: 13
Location: 日本
znatz 08 Jul 2012, 10:57
But if I comment out the call [ExitProcess] ,
the same error message shows up again.


Description:
Download
Filename: mydll.ASM
Filesize: 649 Bytes
Downloaded: 389 Time(s)

Post 08 Jul 2012, 10:57
View user's profile Send private message AIM Address Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 08 Jul 2012, 11:11
The import macros of FASM imports the function only if it is used somewhere in the source. If you don't use any API function, the the import section will be empty and Windows will complain.

One of the workarounds is to use:
Code:
virtual at 0
  call [ExitProcess]
end virtual    


This way, the ExitProcess will be imported, but the call will not be defined in the binary.

The other way is to simply work on your dll, until you need some API function and then to import it - this will fix the issue in "natural way".
Post 08 Jul 2012, 11:11
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Jul 2012, 22:13
There is an even shorter method:
Code:
dummy = ExitProcess    
Now fasm will detect ExitProcess symbol as used and therefore the macro will proceed to import the function as requested.
Post 08 Jul 2012, 22:13
View user's profile Send private message Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 09 Jul 2012, 05:32
LocoDelAssembly wrote:
There is an even shorter method:
Code:
dummy = ExitProcess    
!? Smile
force relocation instead as suggested 100 times in other threads
correct would be
Code:
format PE GUI 4.0 DLL
entry DllEntryPoint
include 'win32a.inc'
section '.text' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
  mov eax,TRUE
  ret
endp

proc myFC
    ret ;Do nothing
endp 
mov eax,myFC ;<-- force it

section '.edata' export data readable
  export 'mydll.dll',\
    myFC,'myFC'
section '.reloc' fixups data discardable
    

Cheers,

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 09 Jul 2012, 05:32
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 09 Jul 2012, 05:55
All these problems appears only on empty test DLLs. If the library contains more or less useful code, everything will be OK, without using these all tricks.
I write DLLs very often on my job and never had any problems with above issues.

So, the moral is: "Write more, think less." Laughing
Post 09 Jul 2012, 05:55
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode 09 Jul 2012, 06:07
JohnFound wrote:
So, the moral is: "Write more, think less." Laughing

de facto, is so overbloated the code you write that, as in the above case, when giving hints to people who needs it, the wrong way is called "JohnFound". i suspect it is your faking job
about understimating the help people really need.

_________________
⠓⠕⠏⠉⠕⠙⠑
Post 09 Jul 2012, 06:07
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.