Hi @ll,
i'm currently playing around with coding dlls in masm (and of course calling dlls ;)). I wanted to start with a simple example, to test if it works and then building a more complex dll. Actually I want to call the DLL from Delphi, but it doesn't work, so i thought in asm it would work, but no way :(
So here's my code:

Example Code:


includelib capture.lib
CapScreen PROTO :DWORD

.data
Hello db "Hello World!",0

.code
start:
invoke CapScreen, Hallo
invoke ExitProcess,NULL
end start


The DLL-Code


DllEntry proc hInstance:HINSTANCE, reason:DWORD, reserved1:DWORD
mov eax,TRUE
ret
DllEntry ENDP

CapScreen Proc lpFileName:DWORD
invoke MessageBox, 0, addr lpFileName, NULL, 0
ret
CapScreen endp

End DllEntry

And the DEF-File:


LIBRARY capture
EXPORTS CapScreen


Waiting for some great help ;)
DaEagle99
Posted on 2001-11-28 07:14:37 by DaEagle99
You have a number of problems. First, you define the variable "Hello",
but you use the variable "Hallo" in the invoke call. Also, you should
use "offset Hello", not just "Hello" (otherwise you'd, if masm doesn't
give an error, put data from the string onto the stack, instead of
the pointer to the string).

In your DLL code, you use ADDR. Not good, your *string* is not
stored on the stack, a *pointer* to the string is. Thus, you should
use:



CapScreen Proc lpFileName:DWORD
invoke MessageBox, NULL, [lpFileName], NULL, MB_OK
ret
CapScreen endp


Hope this helps :)
Posted on 2001-11-28 07:54:42 by f0dder
Hey f0dder,
your reply was exactly this, what i was looking for :alright:!
Now it works without any problems, cool :grin:
You're right that i used "Hallo", because i've just translated this from german to english for this forum.

But now I've got some general questions in DLL programming:
1) Do I always have to use instead of ADDR?
2) Why exactly do I have to call offset "variable" instead of addr "variable"? Should I use this for every MASM project, not just for own dlls?

Thx again,
DaEagle99
Posted on 2001-11-28 08:12:47 by DaEagle99