News:

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

Editing strings

Started by V Coder, December 02, 2005, 09:05:53 AM

Previous topic - Next topic

V Coder

I edit a string s from the inside as follows:

stralloc (numd);
mov (eax, s);
// mov (nums, eax); // *
mov (memaddr, esi); dec (esi);
mov (numd, ecx);
mov (ecx, (type str.strRec [eax]).length);
     wrfl:
mov ([esi+ecx], bl); add ($30, bl); mov (bl, [eax]); inc (eax); dec (ecx); jg wrfl;

fileio.put(fileH, s, " - "); // *
strfree (s);


This copies a BCD number which is stored in normal little-endian format to a string in big-endian format, to output. However, whereas HLA will print the string, it does not allow str.cat or str.insert to add the string to another string or to add to the end of this string.


// str.cat(s, RecordLst);
// str.cat(nl, RecordLst);


Help please.

Sevag.K

Quote from: V Coder on December 02, 2005, 09:05:53 AM
I edit a string s from the inside as follows:

stralloc (numd);
mov (eax, s);
// mov (nums, eax); // *
mov (memaddr, esi); dec (esi);
mov (numd, ecx);
mov (ecx, (type str.strRec [eax]).length);
     wrfl:
mov ([esi+ecx], bl); add ($30, bl); mov (bl, [eax]); inc (eax); dec (ecx); jg wrfl;

fileio.put(fileH, s, " - "); // *
strfree (s);


Here you free 's'

Quote
This copies a BCD number which is stored in normal little-endian format to a string in big-endian format, to output. However, whereas HLA will print the string, it does not allow str.cat or str.insert to add the string to another string or to add to the end of this string.


// str.cat(s, RecordLst);
// str.cat(nl, RecordLst);


Help please.

Here you use str.cat on a string that is no longer guaranteed to be in memory.





V Coder

Sorry.  guess I was not clear. I was getting the problem editing the string before freeing it. Furthermore I was getting problems with sending the string as a Windows message. w.SendMessage or w.MessageBox.

Looking back at Randy's book, I remembered that Windows uses zero-terminated strings. HLA uses zero/length terminated strings. I guess fileio.put just considers the length whereas str.cat and the Windows functions are looking for a zero. I was supposed to zero the byte right after the data in order to create a Windows/HLA valid string - inserting the following code just after "jg wrfl". I'll try it later and report if it works.


mov (0, (type byte [eax]));

V Coder


stralloc (64); // >numd + record string
mov (eax, s1);
// mov (nums, eax); // *
mov (memaddr, esi); dec (esi);
mov (numd, ecx);
mov (ecx, (type str.strRec [eax]).length);
     wrfl:
mov ([esi+ecx], bl); add ($30, bl); mov (bl, [eax]); inc (eax); dec (ecx); jg wrfl;
mov (0, (type byte [eax]));

fileio.put(fileH, s1, " - "); // *

// str.cat(s1, RecordLst);
// str.cat(nl, RecordLst);

w.SendMessage(hwndStatus,w.SB_SETTEXT,0,s1);
// if (lstatus=1) then
// w.MessageBox(NULL,s1,AppName,w.MB_OK);
// endif;


The program works normaly with w.SendMessage, but w.MessageBox causes corruption of the data to a serious extent. Does it interfere with ebp?

str.cat also does not work. It causes immediate crashing. What is the problem?

Sevag.K

The problem might be with the data at memaddr.  There doesn't seem to be anything wrong with the code itself.  I did a quick demo with a static memory for memaddr and it compiled + ran without error.


program tt;
#include ("w.hhf")
#include ("stdlib.hhf")
static
numd :dword := 10;
memaddr :byte; @nostorage; byte "1234567890";
s1 :string;
s2 :str.strvar (200);
endstatic;

begin tt;
mov (str.alloc (64), s1);
mov (&memaddr, esi);
dec (esi);
mov (numd, ecx);
mov (ecx, (type str.strRec[eax]).length);

wrfl: mov ([esi+ecx], bl);
add ($30, bl);
mov (bl, [eax]);
inc (eax);
dec (ecx);
jg wrfl;

mov (0, (type byte [eax]));
w.MessageBox(NULL, s1, NULL, w.MB_OK);
stdout.put (s1, nl);
str.cat (s1, s2);
stdout.put (s2,nl);
end tt;


Randall Hyde

Quote from: V Coder on December 02, 2005, 09:05:53 AM
I edit a string s from the inside as follows:

stralloc (numd);
mov (eax, s);
// mov (nums, eax); // *
mov (memaddr, esi); dec (esi);
mov (numd, ecx);
mov (ecx, (type str.strRec [eax]).length);
     wrfl:
mov ([esi+ecx], bl); add ($30, bl); mov (bl, [eax]); inc (eax); dec (ecx); jg wrfl;

fileio.put(fileH, s, " - "); // *
strfree (s);


This copies a BCD number which is stored in normal little-endian format to a string in big-endian format, to output. However, whereas HLA will print the string, it does not allow str.cat or str.insert to add the string to another string or to add to the end of this string.


// str.cat(s, RecordLst);
// str.cat(nl, RecordLst);


Help please.

Are you zero-terminating the string? Remember, HLA strings have a length prefix AND a zero suffix. This way, they can be passed to Win32 API functions without any other conversion. A few HLA string functions also look for the zero at the end when processing strings of characters (though I don't think that str.cat is one of these, but I may be wrong).
Cheers,
Randy Hyde

V Coder

Apologies. The code to initialize RecordLst was not being executed if the program was run from scratch, only if it was resuming processing a dataset. As a result str.cat was failing.

Having fixed that, the MessageBox is still causing erroneous data and crashing, whereas SendMessage continues to work properly.

Any hints please? Thanks

Sevag.K

Does this happen with any data or just certain data?

V Coder

It happens with any data.

I've just been told that MessageBox (and any dialogs) should not be used within a worker thread. I guess that's what the problem was.

Thanks all.