How to put 2 strings together? I tried to combine path and filename declared as DB and the other as DD and I don't know how to do it. Is it important to deal with DB and DD. Plese help.
Posted on 2001-04-24 13:26:00 by raguru
Nope, not important at all... erm.. yes it is.. db which is a synonym for BYTE (always write out everything - don't rely on abreviations) dw means WORD (2 bytes) dd means DWORD (4 bytes) Now for the combining : if you declare strings as: MeMyselfAndI BYTE "JimmyClif",0 ExtraOne BYTE " :) ",0 Buffer BYTE 50 dup(?) and you want to combine them you use lstrcat invoke lstrcpy,ADDR Buffer,ADDR MeMyselfAndI invoke lstrcat,ADDR Buffer,ADDR ExtraOne and you get: "JimmyClif :)",0 in your buffer PS: I suggest taking a look at the masm32.hlp for more data types ;)
Posted on 2001-04-24 14:20:00 by JimmyClif
Uh... I've taken quite a long time writing these few words *hehehe* Rafe meant the szCatStr function available in masm.lib it works exactly the way lstrcat works.. (it's just shorter I suppose)
;)
Posted on 2001-04-24 14:25:00 by JimmyClif
raguru, The basics of joining strings is that they all must be strings first. String data is mainly BYTE data (UNICODE strings are different). If you want a string to display somewhere that has text and numeric results together, convert the numeric results to string first, then concantenate them together. Jimmy mentioned one function from the MASM32 library szCatStr, this is a traditional string joining function that does one string append at a time but Alex (TheSvin) wrote a function for the MASM32 library called szMultiCat that will join multiple strings at a time. Works like this, allocate a buffer large enough on the stack to take all of the string data you want to put into it,

    LOCAL buffer[128]:BYTE        ; main buffer
    LOCAL numresult[12]:BYTE      ; for converted number
Set its initial length to zero by putting an ASCII zero at the beginning of it,

    mov buffer[0], 0
Create you leading and trailing strings in either the .DATA section or cheat and use the szText MACRO.

    szText LeadText,"This file opened at "
    szText TrailTxt," bytes"
Convert the number into the string buffer allocated for it,

    invoke dwtoa,My_DWORD_Number,ADDR numresult
Then concantenate them all together into one string so that you can display it in your program.

    invoke szMultiCat,3,ADDR buffer,ADDR LeadText,ADDR numresult,ADDR TrailTxt
and Viola ! you have the string ready to display in your app.

    This file opened at 8192 bytes
Regards, hutch@pbq.com.au
Posted on 2001-04-24 20:21:00 by hutch--
I wrote: .DATA FinalFile db "\atest.exe",0 .DATA? WinSysPath dd ? ProcName dd ? FinalAddr dd ? .CODE invoke GetSystemDirectory,addr WinSysPath,MAX_PATH invoke MessageBox, NULL,addr WinSysPath, addr MsgCaption, MB_OK ;this returns right value invoke GetModuleFileName,NULL,addr ProcName,128 invoke MessageBox, NULL,addr ProcName, addr MsgCaption, MB_OK ;this returns right value invoke lstrcpy,addr FinalAddr,addr WinSysPath invoke lstrcat,addr FinalAddr,addr FinalFile invoke MessageBox, NULL,addr FinalAddr, addr MsgCaption, MB_OK ;this returns rubbish why?
Posted on 2001-04-25 16:05:00 by raguru
Hello.. I didn't check your API-Calls now, but replace this:

.DATA?
WinSysPath dd ?
ProcName dd ?
FinalAddr dd ? 
with this:

.DATA?
WinSysPath BYTE 56 dup(?)
ProcName BYTE 56 dup(?)
FinalAddr BYTE 128 dup(?)
Re-Read Hutch's answer he gave you.. especially the buffer part of it! When initializing FinalAddress with dd ? you just get 4 bytes space (a 32bit value) - usually used for a handle. If you use FinalAddress BYTE 128 dup(?) you get 128 bytes one after each other where you can save strings and such..
Posted on 2001-04-26 06:24:00 by JimmyClif