News:

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

prob with this test dll

Started by Rainstorm, October 22, 2006, 06:04:16 PM

Previous topic - Next topic

Rainstorm

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

trodon

hi Rainstorm,
you are forget to add
mov eax,TRUE
bofore ret, and because of this you code is crashing on ret!

Regards  :U

Rainstorm

trodon, i can't seem to understand exactly what you mean..
i have;      mov eax, TRUE    in the libmain proc

ty

Rainstorm

trodon

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.....

Rainstorm

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.


PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

Rainstorm

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' ]

Rainstorm

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.

trodon

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

Rainstorm

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


Rainstorm

#10
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

Rainstorm


PBrennick

data is a reserved word, that is why you are getting that error.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Rainstorm

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

MichaelW

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.

eschew obfuscation