The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: georgek01 on September 01, 2005, 03:58:21 PM

Title: Does assembler pad a buffer?
Post by: georgek01 on September 01, 2005, 03:58:21 PM
OK, I've been trying a few things and I'm getting nowhere...

I have a variable szUser db 12 dup (?)

I fill the buffer with data (user name) using GetDlgItemText. Then using SQLBindParameter, I finally pass an SQL statement to a database. If the user enters data of length 12, all works fine. If the user enters anything less than 12, no data is returned. BUT, If I pad the data with spaces in the edit box (to length 12), it works fine.

My question. Does assembler pad the buffer?
Title: Re: Does assembler pad a buffer?
Post by: PBrennick on September 01, 2005, 04:32:25 PM
georgek01,

Move the buffer from .data? to .data and write it like this:
    szUser db 12 dup (20h)

The buffer as you wrote it will be zero filled and evidently this is not desired.

Paul
Title: Re: Does assembler pad a buffer?
Post by: georgek01 on September 01, 2005, 04:34:48 PM
Does the same thing...  :(

If I pad the data with the required amount of spaces, it works.
Title: Re: Does assembler pad a buffer?
Post by: georgek01 on September 01, 2005, 04:57:07 PM
PBrennick,

It appears using szUser db 12 dup (20h) also causes unwanted buffering.

I've even tried trimming (StrTrim) the string before passing it on to the API. Still does the same as before.

Is it possible to dynamically resize the buffer - if so, I could resize the buffer according to the size of the string...?
Title: Re: Does assembler pad a buffer?
Post by: PBrennick on September 01, 2005, 05:34:47 PM
I think you need to explain what unwanted buffering is.  If you start with a buffer of 12 spaces and store 6 characters into it you wind up with a buffer that has 6 characters and is padded to 12 with spaces which is exactly the same as what you originally said you had to do to get it to work.  All I did was simplify it for you and if it worked before it should work now, also, so your comment makes absolutely no sense to me.

If you still have to pad it out with spaces, either you are not explaining this sufficiently or there is a problem elsewhere in your code.

Are you willing to attach the project?

Paul
Title: Re: Does assembler pad a buffer?
Post by: Tedd on September 01, 2005, 06:08:22 PM
What are the parameters that you're passing to SQLBindParameter (meanings and values) ??


"szUser db 12 dup (?)" will create an 'array' with space for exactly 12 characters. The actual contents of that array are not specified or promised, but for now we can assume they are all zero. So szUser = [------------]  (I'm just using - for zero here.)
When you do GetDlgItemText, the contents of the dialog box are copied into the supplied buffer, and ended with a zero (otherwsie how would you know where the end is?) So now szUser = [mr tedd-----]
Note at this point that there are still exactly 12 characters in the array, but only the first 7 have letters (you know it's 7 because the 8th is a zero.)
If you then pad the whole thing with spaces, you will get [mr tedd     ]  which has no zero to indicate the end of the string (but you know it's 12 characters anyway.)

I'm taking a guess here, but I'm assuming the sql function requires you to specify how long the string is, and you're saying 12 each time. When the szUser is 'full' of characters, this works because there really are 12 characters. But when there are less than 12, is fails because you're saying there are 12, but really there are (say) 7 and some extra zeroes.
GetDlgItemText does return the number of (real) characters copied into the buffer, so knowing this is no problem. Maybe you should be telling sql to bind the parameter whose length is the value returned by GetDlgItemText, and not simply 12 every time??
Title: Re: Does assembler pad a buffer?
Post by: PBrennick on September 01, 2005, 06:43:58 PM
Tedd,
That sounds right to me and is pretty much what I suspected.  That is why I wanted to see the source because I know nothing about SQLBindParameter so I needed to see how it is being used.  Thanks for helping.

Paul
Title: Re: Does assembler pad a buffer?
Post by: MichaelW on September 01, 2005, 08:07:30 PM
Perhaps the SQLSTATE value (returned by SQLGetDiagRec) might provide some useful information.

MSDN: SQLBindParameter (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqlbindparameter.asp)

Title: Re: Does assembler pad a buffer?
Post by: PBrennick on September 01, 2005, 08:13:05 PM
Michael,
Thanks for the heads up, it looks like he needs to set the bufferlength parameter in the structure 'on the fly' as a result of what is input.

Paul
Title: Re: Does assembler pad a buffer?
Post by: georgek01 on September 02, 2005, 05:44:26 AM
I really feel stupid. This is a classic case of jumping into something before reading the manual  :red

SQLBindParameter requires the following parameters:

   
   StatementHandle:DWORD,
   InputOutputType:DWORD,
   ValueType:DWORD,
   ParameterType:DWORD,
   ColumnSize:DWORD,
   DecimalDigits:DWORD,
   ParameterValuePtr:DWORD,
   BufferLength:DWORD,
   pStrLenOrIndPtr:DWORD


I was filling the last parameter with SIZEOF szUser - and this is quite legal, OR I can pass (amongst others) SQL_NTS [string is null-terminated]. Once I passed in the latter, all works fine.

Thank you all for your assistance!!
Title: Re: Does assembler pad a buffer?
Post by: Tedd on September 02, 2005, 11:56:57 AM
RTFM :U