News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Making a DLL in MASM32 [Solved]

Started by Lonewolff, March 18, 2016, 06:42:25 PM

Previous topic - Next topic

Lonewolff

Hi guys,

I have created a DLL which is compiling and linking perfectly but the functions 'start' and 'end' don't seem to be exported.

How do I export the functions so they are accessible by other programs?

Full source right here...


.686P
.XMM
.model flat

INCLUDELIB "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86\kernel32.lib"
INCLUDELIB "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x86\ucrt.lib"
INCLUDELIB "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\msvcrt.lib"

QueryPerformanceCounter      PROTO STDCALL :DWORD
QueryPerformanceFrequency    PROTO STDCALL :DWORD

.data?
TimeEnd            DQ 01H DUP (?)
TimeElapsed        DQ 01H DUP (?)
TimeFrequency      DQ 01H DUP (?)
TimeStart          DQ 01H DUP (?)

EXTRN   __alldiv:PROC
EXTRN   __allmul:PROC
EXTRN   __ltod3:PROC

; 'Start' function
_start PROC
push OFFSET TimeFrequency
call DWORD PTR QueryPerformanceFrequency
push OFFSET TimeStart
call DWORD PTR QueryPerformanceCounter
fldz
ret 0
_start ENDP

; 'End' function
_TEXT SEGMENT
tv165 = -8
_end PROC
push ebp
mov ebp, esp
sub esp, 8
push OFFSET TimeFrequency
call DWORD PTR QueryPerformanceFrequency
push OFFSET TimeEnd
call DWORD PTR QueryPerformanceCounter
mov ecx, DWORD PTR TimeEnd
sub ecx, DWORD PTR TimeStart
mov eax, DWORD PTR TimeEnd+4
sbb eax, DWORD PTR TimeStart+4
push 0
push 1000000000
push eax
push ecx
call __allmul
push DWORD PTR TimeFrequency+4
push DWORD PTR TimeFrequency
push edx
push eax
call __alldiv
mov ecx, eax
mov DWORD PTR TimeElapsed, eax
mov DWORD PTR TimeElapsed+4, edx
call __ltod3
movsd QWORD PTR tv165[ebp], xmm0
fld QWORD PTR tv165[ebp]
mov esp, ebp
pop ebp
ret 0
_end ENDP
_TEXT ENDS
END


I am compiling it with these commands


Ml.exe /c /coff source.asm
Link.exe /SUBSYSTEM:WINDOWS /DLL source.obj


So as I said, I am getting a dll file created happily but cant access the two functions.

Any help would be greatly appreciated.  :biggrin:

Lonewolff

Worked it out.  8)

Apparently you need to use 'polink' and also manually create an export table.

Unless there is an easier way.

TWell

Create Def file for linker?
EXPORTS
start
end

sinsi

Does this work?
_start PROC EXPORT

Taken from here.
Tá fuinneoga a haon déag níos fearr :biggrin:

jj2007

include \masm32\include\masm32rt.inc

.code
LibMain proc instance:DWORD, reason:DWORD, unused:DWORD
    return 1
LibMain endp

SayHi proc syscall export pText, pTitle, mode
invoke MessageBox, 0, pText, pTitle, mode
ret
SayHi endp

end LibMain


Save as TestMe.asm, then use attached batch file.

Testcode (also attached):

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Dll "TestMe"
  Declare SayHi, 3
  Inkey Str$("Sayhi returned %i", SayHi("What do you want to return?", "SayHi:", MB_YESNOCANCEL))
EndOfCode