So, i have this dll file called dllFile.dll. Inside this dll file there is this function called dllFile() which i will call from my main program.

So i first extract the function into a library file dllFile.lib using the linker options:
link /lib /def:dllFile.def


And the contents of the dllFile.def definition file is:
LIBRARY dllFile.dll
EXPORTS dllFile


Now that i have my library file i just link it with my main program and it links successfully but when i try to open the program it crashes giving me an error.

The dll file happens to be made by me so i have the source code. If i directly create a library from the source code instead extracting it from the dll and then compile it back with my main program it works.
ml dllFile.asm /link /noentry /dll /out:dllFile.dll /def:dllFile.def
ml main.asm /link /subsystem:console /entry:main


The problem is that this dll file happens to be made by me. So, if i were to have a dll file and only have it's function names in a definition file (.def) then i wont be able to make it work properly because it crashes. So, i am wondering what i am doing wrong.

(dllFile.asm)
.586
.model flat, c

includelib kernel32.lib

.code
public dllFile
dllFile proc,
lpBuffer:dword,
nNumberOfCharsToWrite:dword,
lpNumberOfCharsWritten:dword

STD_OUTPUT_HANDLE equ -11
extrn GetStdHandle@4:near
push STD_OUTPUT_HANDLE
call GetStdHandle@4

extrn WriteFile@20:near
push 0
push lpNumberOfCharsWritten
push nNumberOfCharsToWrite
push lpBuffer
push eax
call WriteFile@20

extrn ExitProcess@4:near
push 0
call ExitProcess@4
dllFile endp
end


(main.asm)
.586
.model flat

includelib dllFile.lib

.data
bytesWritten dword ?
printStr byte "This better work!",0Ah,0
printStrSize equ lengthof printStr

.code
main proc
push offset bytesWritten
push printStrSize
push offset printStr
extern _dllFile:near
call _dllFile
main endp

end
Posted on 2011-01-10 08:39:47 by banzemanga
Nevermind, i found what i was doing wrong.

I linked the dll without the definition file:

ml dllFile.asm /link /dll /noentry /out:dllFile.dll


If i actually dump the function names i don't get the function name dllFile():
link /dump /exports dllFile.dll


The right way to do it is to link the dll file with the definition file. Although when linking a dll file with a definition file, it automatically creates the library file; when i dump the function names i do get the dllFile() function:
ml dllFile.asm /link /noentry /dll /out:dllFile.dll /def:dllFile.def
del dllFile.lib
link /dump /exports dllFile.dll


With the dll file (dllFile.dll) linked with definition files i could link a library file out of it with no problems and link it to the main program.
link /lib /def:dllFile.def
ml main.asm /link /subsystem:console /entry:main
Posted on 2011-01-10 09:54:32 by banzemanga