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.
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 ;)
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)
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,
Set its initial length to zero by putting an ASCII zero at the beginning of it,
LOCAL buffer:BYTE ; main buffer LOCAL numresult:BYTE ; for converted number
Create you leading and trailing strings in either the .DATA section or cheat and use the szText MACRO.
mov buffer, 0
Convert the number into the string buffer allocated for it,
szText LeadText,"This file opened at " szText TrailTxt," bytes"
Then concantenate them all together into one string so that you can display it in your program.
invoke dwtoa,My_DWORD_Number,ADDR numresult
and Viola ! you have the string ready to display in your app.
invoke szMultiCat,3,ADDR buffer,ADDR LeadText,ADDR numresult,ADDR TrailTxt
This file opened at 8192 bytes
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?
Hello.. I didn't check your API-Calls now, but replace this:
.DATA? WinSysPath dd ? ProcName dd ? FinalAddr dd ?
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..
.DATA? WinSysPath BYTE 56 dup(?) ProcName BYTE 56 dup(?) FinalAddr BYTE 128 dup(?)