News:

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

string pointer using lstrcpy and lstrcat please.

Started by gavin, July 15, 2005, 01:53:15 PM

Previous topic - Next topic

gavin

Hi Guys.

I've read a lot but can't figure this part out.


invoke SendMessage,hWnd,LB_GETSEL,ecx,0
cmp eax, 0            ; compare eax to 0
jne found             ; jump to found if not equal

found:
mov eax, ip[ecx*4] ;ip is an array of pointers to strings.



invoke lstrcpy,

invoke lstrcat,

I need to put the string pointed to by eax onto the end of another string.
Thanks alot.

Also is their an updated text on the masm syntex around?

Mark Jones

Hi Gavin, do you have the WIN32.HLP file? It explains how to call lstrcat.


The lstrcat function appends one string to another.

LPTSTR lstrcat(

    LPTSTR lpString1, // address of buffer for concatenated strings
    LPCTSTR lpString2 // address of string to add to string1
   );

Parameters:

lpString1

Points to a null-terminated string. The buffer must be large enough to contain both strings.

lpString2

Points to the null-terminated string to be appended to the string specified in the lpString1 parameter.


Return Values: If the function succeeds, the return value is a pointer to the buffer.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

See Also: lstrcmp, lstrcmpi, lstrcpy, lstrlen


This works in MASM as:


.data
    String1  DB  'Hello World! ',0
             DB  32 DUP(0)              ; reserve extra space for String2
    String2  DB  'Win32 Assembly is Great! ',0
.code
    mov eax, offset String2             ; pointer of String2 in eax
    invoke lstrcat, ADDR String1, eax               ; combine them

    invoke MessageBox, 0, addr String1, 0, MB_OK    ; display result


:bg
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gavin

Hiya.
Thanks for the help so far much appreciated.

FileName db "C:\Program Files\Valve\Steam\Steam.exe ",0 ;program to run
        server  db  70 DUP(0)
        command db "-applaunch 10 +connect ",0               ; comand string
         
        ip0 db "213.40.198.1:27020 ",0
        ip1 db "213.40.198.1:27040 ",0
        ip2 db "213.40.198.1:27045 ",0
        ip3 db "213.40.198.1:27035 ",0
        ip4 db "213.40.198.1:27030 ",0
        ip5 db "213.40.198.1:27025 ",0
        ip6 db "213.40.198.1:27015 ",0
       
        ip DWORD ip0, ip1, ip2, ip3, ip4, ip5, ip6  ;array of pointers to above


What i have working so far is it loads the game steam.exe with the command also but without the ip address to connect to..


invoke SendMessage,hWnd,LB_GETSEL,ecx,0
cmp eax, 0            ; compare eax to 0
jne found             ; jump to found if not equal

found:
mov eax, ip[ecx*4]   ;eax holds the address to the selected item right?

invoke lstrcat,ADDR command,eax ; what i'm trying to do is append the ip onto the command.

invoke ShellExecute,0,0,ADDR FileName,ADDR command, NULL, SW_SHOWNORMAL

Iit's my first program :)

I'm learning all i can as i go thanks for your help.


It should look like this.

C:\Program Files\Valve\Steam\Steam.exe -applaunch 10 +connect [ip address goes here].

Any ideas lads?

tekhead009

Nevermind, you've got it right. I didn't see the 70 byte "server" buffer you created after the FilePath.
I had originally posted saying you should create a buffer, but then when I wen't to play with your code I saw you had created one in the .data section.


invoke MessageBox,NULL,OFFSET FileName,OFFSET szCaption,MB_OK
invoke lstrcat,OFFSET FileName, OFFSET command
invoke MessageBox,NULL,OFFSET FileName,OFFSET szCaption, MB_OK
mov EAX,2
mov ECX,OFFSET ip
invoke  lstrcat,OFFSET FileName, [ECX + (EAX * 4)]
invoke MessageBox,NULL,OFFSET FileName,OFFSET szCaption, MB_OK


Another edit, just to confuse anybody who's been reading this post.
Assuming EAX holds the list number of the IP address that has been selected 0, 1, 2, 3, etc.., the code above works to select the related IP address in the array. If that's where you were having problems with your code, otherwise ignore my post.

I first get the offset of IP into ECX.
Then to reference it [ECX] would be the first IP address in that array.
Take the selected list number, and multiply it by 4 because there are 4 bytes in each word. [ECX + (EAX * 4)] points to the offset you need for the correct string.

I'm really sorry if I confused things, I'm a terrible new person.

gavin

Hi .
Thanks for the help.

I'm not sure what your code is for above?
Thanks.

tekhead009

Yeah, I edited it again, is it any more clear now? I should stop that; sorry.  :(

gavin

Hey no problem man.
You have been a very good help to me.
I'll try your code now and get back to you ;) :U

Mark Jones

#7
Another approach might be this:


.data
    lpszFileName    db  'C:\Program Files\Valve\Steam\Steam.exe',0
    lpszCommand     db  '-applaunch 10 +connect 213.40.198.1:27000',0

.code
    mov eax, offset lpszCommand     ; pointer as eax
    add eax, 40                     ; increment to the last two zeroes
    mov word ptr [eax], "52"        ; make the last two digits a "25" or whatever
   
    invoke ShellExecute,0,0,addr lpszFileName,addr lpszCommand,0,SW_SHOWNORMAL


Edit: small typo, sorry. :bg
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gavin

Hi Mark.

The way you do it is brilliant thanks man.
:U
I'm nearly finshed my first program thanks

gavin

Mark thanks to you my code is done now.
Your a great help to me.
:U :wink

Mark Jones

You're welcome Gavin. :bg

Just keep coding, and soon you'll be teaching the rest of us things. :toothy
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gavin

Ha i hope so  :lol
Mark What books sites would you know for me?
All the stuff i have is ancient also is the masm 6.1 docs worth reading or are they to old?



gavin

Thanks Roticv nice link ! :U
Read some good stuff their earlier thanks.

GregL

gavin,

Quote
... is the masm 6.1 docs worth reading or are they to old?

Absolutely worth reading, both the Programmer's Guide and the Reference. It all still applies, very few changes were made, mainly stuff was added (.686, .MMX, .XMM etc.). There is some documentation for the later versions too.