The MASM Forum

General => The Campus => Topic started by: x64Core on May 29, 2012, 01:45:52 PM

Title: Creating a DLL without Dependencies
Post by: x64Core on May 29, 2012, 01:45:52 PM
Hello all guys, fine, I'm trying create a DLL without dependencies :P
but, it adds MSVCRT.DLL:
(http://img688.imageshack.us/img688/9899/mydllscreen.png)

then, exist a way to create it without MSVCRT.DLL?
the DLL is right, has a size of 3kb wow!

any words, thanks !  :biggrin:


code:

include masm32rt.inc

.data
mymsg db "Hello world from DLL :D",0
.code
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD
    invoke MessageBox,NULL,addr mymsg,addr mymsg,MB_OK
    ret
DllEntry Endp


End DllEntry


Title: Re: Creating a DLL without Dependencies
Post by: P1 on May 29, 2012, 02:43:37 PM
Quote from: RHL on May 29, 2012, 01:45:52 PM
Hello all guys, fine, I'm trying create a DLL without dependencies :P
but, it adds MSVCRT.DLL:
(http://img688.imageshack.us/img688/9899/mydllscreen.png)

then, exist a way to create it without MSVCRT.DLL?
the DLL is right, has a size of 3kb wow!

any words, thanks !  :biggrin:


code:

include masm32rt.inc

.data
mymsg db "Hello world from DLL :D",0
.code
DllEntry proc hInst:HINSTANCE, reason:DWORD, reserved1:DWORD
    invoke MessageBox,NULL,addr mymsg,addr mymsg,MB_OK
    ret
DllEntry Endp


End DllEntry

That is easy, just don't use ANY Windows API functions or procedures, including MessageBox.

Regards,  P1   8)
Title: Re: Creating a DLL without Dependencies
Post by: x64Core on May 29, 2012, 02:53:40 PM
but why? in a Portable Executable I can do the same,
and it does not require of MSVCRT.DLL.... :(
Title: Re: Creating a DLL without Dependencies
Post by: dedndave on May 29, 2012, 02:56:43 PM
well - msvcrt should not be getting pulled in
it looks as though you have a call to the "wait_key" macro or something
i build it here - and the only dependency is user32.dll

what ML and LINK command lines are you using ?
ml /c /coff dll.asm
link /dll /subsystem:windows dll.obj

is what i used
if there were any exported functions, you'd also want a DEF file and use...
link /dll /def:dll.def /subsystem:windows dll.obj

Bill Cravener has a nice little example
\masm32\examples\Bill_Cravener\mvolume

what program are you using to see the dependencies ?
Title: Re: Creating a DLL without Dependencies
Post by: x64Core on May 29, 2012, 03:11:33 PM
Hello Dave  :biggrin:
thanks bro, yeah that's right!  :shock: I'm using CFF explorer, it's very good :P
(http://img214.imageshack.us/img214/1885/ndsodo.png)

is rare... only I deleted the invoke line of menssagebox, assemble, and look at the exe, then came back to write the line
and gave me this result  :icon_eek:

but now:

(http://img838.imageshack.us/img838/6092/noexpro.png)

is created the export table :|
why?, I'm not export any function...


Title: Re: Creating a DLL without Dependencies
Post by: x64Core on May 29, 2012, 03:19:32 PM
surely, it are  in the newer versions of MASM, because I do not have them :P
Title: Re: Creating a DLL without Dependencies
Post by: hutch-- on May 29, 2012, 03:21:25 PM
RHL,

The reason why you are getting MSVCRT included is because it is contained in the MASM32RT include file. The way to avoid this is to include specific include file AFTER windows.inc.


Include \masm32\include\windows.inc  ; always first
Include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
etc etc ....
Title: Re: Creating a DLL without Dependencies
Post by: dedndave on May 29, 2012, 03:27:06 PM
i am afraid that Hutch and i are not on the same page, here - lol
i don't think any libs are imported unless a function is used

as for the export table...
i guess it assumes you are going to have an exported function
maybe if you create a DEF file that has no exports - only the DLL name
Title: Re: Creating a DLL without Dependencies
Post by: x64Core on May 29, 2012, 03:43:05 PM
yeah, that's right  :icon_redface:
thanks a lot guys, really I appreciate your help
Title: Re: Creating a DLL without Dependencies
Post by: hutch-- on May 29, 2012, 05:08:33 PM
This is the catch, if your DLL does not call the OS at all, then you have no imports but as soon as it does you need the import library for any API function that you call. You can try risky and unreliable methods but you live dangerously doing so.
Title: Re: Creating a DLL without Dependencies
Post by: Vortex on May 30, 2012, 03:55:56 AM
Hi RHL,

Here is a quick example for you. The DLL in the attachment does not import any function. It exports only one function named StrLen.