If I have a ten byte mem chunk that contains the following:

00 00 01 31 05 DB 0A 45 68 F3

and the first four bytes designate the IPX network number and the last six bytes designate the MAC address of the network card, how would I convert this straight into the format:


for displaying in a MessageBox or the like.

I tried wsprintf with this as the template:


but it comes out crazy like this:


or something. Am I missing something? I dumped the mem block into a file and checked it with a hex editor and it looks just like at the top of the message. thx.
Posted on 2002-01-08 19:03:49 by rdaneel
I think you should use an lstrcat.

invoke wsprintf,addr storage,addr szformat, addr string
invoke lstrcat, addr completestorage, addr storage

I think this should work. storage must be in .data? section. completestorage can be in .data, and is the string in which you are going to add storage, for example: "completestorage: storage", so: "address: 05....etc".

Tell us if it works or not. Sorry if this is not correct, just tell me if not, and i will check it again.

See you
Posted on 2002-01-08 19:14:50 by CodeLover
rdaneel, that looks right, but try this, too?

I have a project here that uses:
"%s, %lu, %lu%.9lu !"

...and it appears as expected.

Edit: Whoops, forgot that wsprintf doesn't truncate numbers that are bigger, so it's trying to convert a 32-bit number in each case and filling the possition with as many significant figures as it has or two - which ever is greater. This won't work - ignore me. :grin:

From the PSDK:
The width specification never causes a value to be truncated. The value is not truncated when the number of digits exceeds the specified precision
Posted on 2002-01-08 20:07:32 by bitRAKE
Each of the bytes must be expanded (zero padding) to a DWORD before they are used as arguments to wsprintf.
Posted on 2002-01-08 22:54:18 by tank
tank is correct.

szFormat db "%02X-%02X-%02X-%02X:%02X-%02X-%02X-%02X-%02X-%02X",0
MemMac db 00h, 00h, 01h, 31h, 05h, 0DBh, 0Ah, 045h, 068h, 0F3h
szMacAddy db 40 dup (0)


mov ecx, 10 ;10 bytes

movzx eax, byte ptr [MemMac+ecx]
push eax
dec ecx
jnz @b

push offset szFormat
push offset szMacAddy
call wsprintf
add esp, 4*(2+10) ;fix stack

invoke MessageBox, 0, addr szMacAddy, 0, MB_OK
Posted on 2002-01-09 07:17:35 by savage
Thanks everyone. It works fine now. So that means that wsprintf takes a DWORD value only. Either a DWORD address of a string in mem. or a DWORD integer value but it has to be a DWORD value for each argument. That makes sense. Most all the functions in the api take dword arguments don't they. Thanks again.
Posted on 2002-01-09 08:28:16 by rdaneel