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

PBrennick

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

AkinforASM

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

Rainstorm

hi Paul,

Thanks for the info & perspective on the whole thing. :)

MichaelW, thnks , that answered my Query.

Rainstorm.

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

Rainstorm

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