Is there a way to export a function with the stdcall convetion (including the number of parameteres) from MASM without using PROC?

I've been trying this:

PUBLIC STDCALL strlen

strlen:
...code
ret

But it only generates _strlen as the symbol because the assembler doesn't know the parameter list, I have it working appending @4 to the function, is there another way?

Regards,
Mariano.
Posted on 2004-05-29 13:13:09 by Eternal Idol Birmingham
Here is a quick example:


.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc

public StdOut@4
.code

StdOut@4:
push ebp
mov ebp,esp
add esp,-12 ;3 dwords
; LOCAL hOutPut :DWORD
; LOCAL bWritten :DWORD
; LOCAL sl :DWORD

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [ebp-4], eax ; hOutPut

invoke lstrlen,[ebp+8] ; lpszText
mov [ebp-12], eax

lea eax,[ebp-8] ; bWritten
invoke WriteFile,[ebp-4],[ebp+8],[ebp-12],eax,NULL ; [ebp-12] = sl
mov eax,[ebp-8]
leave
ret 4

end




.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

StdOut PROTO :DWORD

.data

Message db 'Hello my friend!',0

.code

start:

invoke StdOut,ADDR Message
invoke ExitProcess,0
END start


To build the example:


ml /c /coff Hello.asm
ml /c /coff func.asm
link /SUBSYSTEM:CONSOLE Hello.obj func.obj
Posted on 2004-05-29 16:44:08 by Vortex
how about this variant? :



option prologue: none
option epilogue: none

PUBLIC STDCALL strlen

strlen: ; strlen(:DWORD)

push ebp
mov ebp, esp
;...
mov eax, [ebp+8] ; first param
add eax, "test"
;...
mov esp, ebp
pop ebp

ret

option prologue: PrologueDef
option epilogue: EpilogueDef


export name is 'strlen'
and fully control variables
Posted on 2004-05-29 16:50:50 by Funbit
Thanks Vortex but that's exactly what I was doing, I meant another way.

"But it only generates _strlen as the symbol because the assembler doesn't know the parameter list, I have it working appending @4 to the function, is there another way?"
Posted on 2004-05-29 17:16:07 by Eternal Idol Birmingham

how about this variant? :



option prologue: none
option epilogue: none

PUBLIC STDCALL strlen

strlen: ; strlen(:DWORD)

push ebp
mov ebp, esp
;...
mov eax, [ebp+8] ; first param
add eax, "test"
;...
mov esp, ebp
pop ebp

ret

option prologue: PrologueDef
option epilogue: EpilogueDef


export name is 'strlen'
and fully control variables


I don't know if I'm making a mistake but it stills exports _strlen. Thanks anyway.
Posted on 2004-05-29 17:49:10 by Eternal Idol Birmingham
heh...
did u use .def file?

if not - u need to create it, like this (testdll.def):

LIBRARY testdll
EXPORTS strlen

and compile dll with this command line:

p:\masm32\bin\ml /c /coff testdll.asm
p:\masm32\bin\Link /SUBSYSTEM:WINDOWS /DLL /DEF:testdll.def testdll.obj

try
Posted on 2004-05-29 18:22:48 by Funbit

heh...
did u use .def file?

if not - u need to create it, like this (testdll.def):

LIBRARY mytestdll
EXPORTS strlen

and compile dll with this command line:

p:\masm32\bin\ml /c /coff testdll.asm
p:\masm32\bin\Link /SUBSYSTEM:WINDOWS /DLL /DEF:testdll.def testdll.obj

try


No, I didn't use a .def file and I'm building a static library, thanks anyway I've solved it.
Posted on 2004-05-29 18:29:11 by Eternal Idol Birmingham