hi..
this is just a test dll
am having probs withis code..its not returning the text as it should on the app.
testrun PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.data
linne1 db "test run..",0
.data?
; hInstance dd ?
.code
; --------------------------------------------------------------------
LibMain proc hinstance:DWORD,reason:DWORD,unused:DWORD
mov eax, TRUE
ret
LibMain endp
testrun proc mWnd:DWORD,aWnd:DWORD,data:DWORD,parms:DWORD,show:BOOL,nopause:BOOL
mov ecx, offset linne1 ; get the address of linne1
mov data, ecx ; pass the pointer on into the data variable
mov eax, 3 ; return 3 to indicate that the DLL has filled the data variable with the
; result that $dll() as an identifier should return
ret
testrun endp
-----------------------X------DeF File---------------------------X----------------------------------X--------------
LIBRARY dll_test
EXPORTS testrun
-----------------------------------------------------------------------------------------------------------------------
thanks
Rainstorm
hi Rainstorm,
you are forget to add
mov eax,TRUE
bofore ret, and because of this you code is crashing on ret!
Regards :U
trodon, i can't seem to understand exactly what you mean..
i have; mov eax, TRUE in the libmain proc
ty
Rainstorm
Quote from: Rainstorm on October 22, 2006, 06:40:17 PM
trodon, i can't seem to understand exactly what you mean..
i have; mov eax, TRUE in the libmain proc
ty
Rainstorm
oh sorry i was dont see :red
btw can you post more code, for example your mov data, ecx ( i dont know what is data ) etc.....
hi trodon,..
i posted the complete code..
am just learning about dlls..
while looking at some procs in the masm32 dir, they don't define the variable..so i thought that was
automatic or something..
if you mean the meanings of the stuff in testrun proc, theen here it is.
The routine in the DLL being called must be of the form:
int __stdcall procname(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
data is the information that you wish to send to the DLL. On return, the DLL can fill this variable with the command it wants mIRC to perform if any.
What trodon means is you must be attempting to assemble 'something,' what you posted would never assemble so please post the entire source file. I happen to agree with him, it is because of situations such as these that I will not attempt to help unless I can see the entire file. Your explanation is unremarkable.
Paul
I posted the whole source file of my code in the first post.
do i have to declare the 'data' variable ?
edit: [ this is the only line i forgot to add in the code i possted at the end 'end LibMain' ]
was just trying a dummy kind of dll..where it would return the string 'test run..' to the calling
application.
can you tell me what is wrong ?
what i posted is the whole code.
Rainstorm, your code is not finished and also not even started and because of that i cannot help you and PBrennick also,
first of all your Libmain proc is returning and not have code to call testproc!
also your code not have even .if reason == DLL_PROCESS_ATTACH, detach etc...
my advice to you is to check masm32 folder with examples, there you have minimal example .dll file
location is:
C:\masm32\examples\exampl01\dll
regards :U
hi...trodon , paul
yes trodon, i had looked at it before & am still reading..
earlier i had skipped the DLL_PROCESS_ATTACH line since it wasn't there in the iczelion testdll code.
don't understand all aspects of it but will ask those questions later
I modified the code a bit & after calling the dll from the application it seems to be
returning the value :))) ....so i guess that means the dll code works somewhat :))
here's the code
;------Include Files etc here----------------------
testrun PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.data
linne1 db 50
.data?
hInstance dd ?
.code
; -------------------------------------------------------------------------------------------
LibMain proc instance:DWORD,reason:DWORD,unused:DWORD
.if reason == DLL_PROCESS_ATTACH
push instance
pop hInstance
mov eax, TRUE
.elseif reason == DLL_PROCESS_DETACH
.elseif reason == DLL_THREAD_ATTACH
.elseif reason == DLL_THREAD_DETACH
.endif
ret
LibMain endp
testrun proc mWnd:DWORD,aWnd:DWORD,data:DWORD,parms:DWORD,show:BOOL,nopause:BOOL
mov ecx, dword PTR linne1
mov edx, [data] ; put the pointer into edx
mov [edx], ecx
mov eax, 3 ; mov 3 into eax to indicate that the DLL has filled the data variable with the
; result that $dll() as an identifier should return
ret
testrun endp
; -----------------------------------------------------------------------------------------------------------------------
end LibMain
..in the app from which i am calling the dll, it returns 2 since 50 is the ascii value
:)))) means i got something right at least..& it actually worked!
Rainstorm
hi,..
am just fiddling with the code I wrote to understand what's going on better..& the following code fails
for this line - mov edx, offset data - i get the error
error A2098: invalid operand for OFFSET
testrun PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.data
linne1 db 50
.data?
hInstance dd ?
.code
; ---------------------------------------------------------------------
LibMain proc instance:DWORD,reason:DWORD,unused:DWORD
.if reason == DLL_PROCESS_ATTACH
push instance
pop hInstance
mov eax, TRUE
.elseif reason == DLL_PROCESS_DETACH
.elseif reason == DLL_THREAD_ATTACH
.elseif reason == DLL_THREAD_DETACH
.endif
ret
LibMain endp
testrun proc mWnd:DWORD,aWnd:DWORD,data:DWORD,parms:DWORD,show:BOOL,nopause:BOOL
mov ecx, dword PTR linne1
mov edx, offset data
mov [edx], ecx
mov eax, 3
ret
testrun endp
end LibMain
Ty
got that one sorted out...
data is a reserved word, that is why you are getting that error.
Paul
someone in the campus forum told me its because i have to use 'lea' for local variables..
i tried it with lea & it worked proper
just a question about that kind of stuff out of curiosity
in my format in the dll I have to use the same words denoted in the format of the calling app ?
like in..
testrun proc mWnd:DWORD,aWnd:DWORD,data:DWORD,parms:DWORD,show:BOOL,nopause:BOOL
would i be able to write it as..for example 'xyz' instead of 'data' ?
testrun proc mWnd:DWORD,aWnd:DWORD,xyz:DWORD,parms:DWORD,show:BOOL,nopause:BOOL
ty
Rainstorm
If you are asking if the called procedure needs to use the same parameter names as the caller, the answer is no, even if the caller is in the same module or application. Parameter names are local to the procedure (i.e. visible only within the procedure), but parameter names, like local variable names, cannot duplicate the name of any variable that is visible within the procedure.
lea (load effective address) has been around for many years but I, also, have noticed that its use can be somewhat quirky at times for no apparent reason (local variables is NOT the problem). Whenever it has caused me a problem, I always switched to the MOV OFFSET syntax (which is also quirky). MOV OFFSET works better than than any other syntax. Attempting to use ADDR should solve local variable problems but that syntax is VERY quirky and also fails every now and then for no apparent reason.
So, as you can see, there is no real definitive answer to this problem. The only place where I have seen ADDR to work consistently is in the parameters of an invoke statement.
Paul
Quote from: Rainstorm on October 28, 2006, 11:27:19 PM
got that one sorted out...
Would you please post your (working) code here?
Because
as a newbie / noob I also tried a dummy dll (involving returning of a string result) but failed since I'm still thinking in the hll fashion thus failed to grasp true rationale of ASM. Now I'm reading everything I find about ASM.
Regards
hi Paul,
Thanks for the info & perspective on the whole thing. :)
MichaelW, thnks , that answered my Query.
Rainstorm.
akinforasm wrote
QuoteWould you please post your (working) code here?
here's the code you were referring to - just a note about this code it won't return the string as it
gets the address of the
data variable, whose value in itself is an address to the buffer.
I was just playing around to make sure that the data variable was a pointer to the buffer & doesn't
carry the data itself - as i wasn't sure about that part in the formaat defined by the calling app. at first.
so it just returns whatever was already filled in the data variable when the call was made
The proper code that returns a value from the dll is in the next post.
---Include Files here---------------------
testrun PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.data
linne1 db 50
.data?
hInstance dd ?
.code
; ---------------------------------------------------------------------
LibMain proc instance:DWORD,reason:DWORD,unused:DWORD
.if reason == DLL_PROCESS_ATTACH
push instance
pop hInstance
mov eax, TRUE
.elseif reason == DLL_PROCESS_DETACH
.elseif reason == DLL_THREAD_ATTACH
.elseif reason == DLL_THREAD_DETACH
.endif
ret
LibMain endp
;--------------------------------------------------------------
testrun proc mWnd:DWORD,aWnd:DWORD,data:DWORD,parms:DWORD,show:BOOL,nopause:BOOL
mov ecx, dword PTR linne1
lea edx, data ; load address of the data variable into edx
mov [edx], ecx ; move the our value into that address space
mov eax, 3
ret
testrun endp
; -------------------------------------------------------------------------
end LibMain
akinasm,
this is the proper code that returns the number 2 in the calling app..
testrun PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.data
linne1 db 50
.data?
hInstance dd ?
.code
; ---------------------------------------------------------------------
LibMain proc instance:DWORD,reason:DWORD,unused:DWORD
.if reason == DLL_PROCESS_ATTACH
push instance
pop hInstance
mov eax, TRUE
.elseif reason == DLL_PROCESS_DETACH
.elseif reason == DLL_THREAD_ATTACH
.elseif reason == DLL_THREAD_DETACH
.endif
ret
LibMain endp
testrun proc mWnd:DWORD,aWnd:DWORD,data:DWORD,parms:DWORD,show:BOOL,nopause:BOOL
mov ecx, dword PTR linne1
mov edx, data ; move the value of the data variable (which is a pointer to the buffer)
; into edx
mov [edx], ecx ; move the value of ecx (50), into the buffer space at edx
mov eax, 3 ; '3' is an option specified by the calling app that says i've filled the buffer
ret
testrun endp
; -------------------------------------------------------------------------
end LibMain