News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Return String From DLL

Started by Force, February 12, 2012, 12:44:29 AM

Previous topic - Next topic

Force

Hi

I am beginner in Assembly

First of all sorry for my broken English

i m trying to send a string to dll  to add another string in dll  and return combined string but it does not work

can anybody help me?

test1.asm
.386
.model flat,stdcall
option casemap:none

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

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib  test2.lib

addProc PROTO:DWORD,:DWORD

.data
test1 db "Masm",0
buffer db 30 dup(0)

.code
start:
invoke addProc,addr test1,addr buffer

invoke MessageBox,NULL,addr buffer,0,0

invoke ExitProcess,NULL
end start


test2.asm (dll)


.386
.model flat,stdcall
option casemap:none

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

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data

test2 db "32",0

.code


start:


addProc proc dnm:LPSTR,dnl:LPSTR
invoke lstrcat,dnl,dnm
invoke lstrcat,dnl,addr test2
ret
addProc endp

end start
Never Stop Until You Are Better Than The Best

clive

Quote from: Force
i m trying to send a string to dll  to add another string in dll  and return combined string but it does not work

What bit is not working, it wouldn't appear you have enough code to make a DLL, or are creating/linking it in a fashion that will work.

http://www.masm32.com/board/index.php?topic=15939.0
It could be a random act of randomness. Those happen a lot as well.

Force

my project is here

Never Stop Until You Are Better Than The Best

Gunner

That is great and all but you don't code a dll the same way you code an exe.  Look at: \masm32\examples\exampl01\dll to see the structure
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Farabi

You can allocate a memory and then return it via eax each time your function called.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

clive

Quote from: FarabiYou can allocate a memory and then return it via eax each time your function called.

Well that'll work, but is prone to be blamed for the memory leaks that inevitably occur. Much better for the caller to provide a buffer, and sizing.
It could be a random act of randomness. Those happen a lot as well.

clive

Quote from: Forcemy project is here

Please revive the tutorial cited in the thread I pointed too, specifcally the DllEntry() part

http://win32assembly.online.fr/tut17.html
It could be a random act of randomness. Those happen a lot as well.

jj2007

That does the job. See in particular the use of labels and end directives.
You need the -lib option, not /dll

.386
.model flat,stdcall
option casemap:none

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

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data
test2 db "32",0

.code
addProc proc dnm:LPSTR,dnl:LPSTR
invoke lstrcat,dnl,dnm
invoke lstrcat,dnl,addr test2
ret
addProc endp

END

Force

Never Stop Until You Are Better Than The Best

Force

i tried it in math.

it works good

code is here
Never Stop Until You Are Better Than The Best

jj2007

Your version chokes if test2.dll is not present. For mine, test2.lib is sufficient, and can be deleted afterwards, i.e. the exe is standalone.

MichaelW

Run-time Dynamic Linking is a better choice if the DLL may not be present and you need to provide the user with a meaningful error message.
eschew obfuscation

Force

Thanks All for Helping

JJ2007  and MichaelW

you were right

I solved problem with LIB option not DLL

it works now as i want

project is here
Never Stop Until You Are Better Than The Best