The MASM Forum

General => The Campus => Topic started by: Lightman on February 09, 2016, 09:50:24 PM

Title: Passing strings to procedures
Post by: Lightman on February 09, 2016, 09:50:24 PM
Hello Everybody,

How do I pass a string to a procedure? For example, I could pass a dword....


MyProc   PROTO  :DWORD



MyProc   PROC   foo:DWORD
   mov   eax, foo
   ...
   ret
MyProc ENDP



invoke   MyProc, 100h


But with a string? Do I just pass the address? But then how, would I reference that in the procedure itself...


MyProc   PROC   msg:DB 1024 DUP('1')
   invoke   MessageBox, hWnd, addr msg, addr AppName, MB_OK
   ...
   ret
MyProc   ENDP




MyProc   PROC  msg:DWORD
   invoke   MessageBox, hWnd, msg, addr AppName, MB_OK
   ...
   ret
MyProc   ENDP


I'm a but confused by this one.

Title: Re: Passing strings to procedures
Post by: dedndave on February 09, 2016, 09:52:50 PM
don't pass the string
pass the address of the string (pointer)

MyProc   PROC   lpszFoo:LPSTR
   mov   eax, foo
   ...
   ret
MyProc ENDP


    INVOKE  MyProc,offset szString