News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

RegQueryValueEx

Started by jj2007, August 27, 2013, 02:16:53 AM

Previous topic - Next topic

Tedd

A quick guess would be the value is sometimes treated as unsigned and others as signed; so, "-1" would be 4294967295 or -1 -- indicating a huge buffer, or none at all (negative size.) If this is the case, you could probably get away with using 2147483647 (7FFFFFFh) as the largest signed value; though some functions may have been ported directly from their original 16-bit ini-file versions and cause further problems, naturally.

Anyway, if you know your buffer size is 'big enough' why not just pass its size straight in? You should already know its size if you know it's big enough.
If you're only expecting a 20 byte string, why say the buffer is any larger? And if it turns out to be larger, that actually should cause an error because it's an unexpected situation that you're not explicitly handling, which will eventually lead to difficult bugs elsewhere.

This is just corner-cutting for the sake of laziness -- do it right or it will (and should) bite you eventually.
Potato2

dedndave

i rarely want to permanently retain the resulting string, anyways
i find it best to:
1) call the function with a null buffer to get the size
2) probe the stack down (as required) to create a temporary buffer
   if you are using the Nt functions, they return UNICODE strings that should be 16-aligned   :t
   so, calculate that alignment into the probe code
3) call the function again with the stack buffer and correct size

good code is bullet-proof - lol
well, almost

i know why Jochen wants to push a -1
it makes for small code   :P

Zen

JOCHEN, 
OK you got it. I was just being annoying. Alex explained perfectly.
Here, is Raymond Chen explaining: More Undocumented Behavior and the People Who Rely On It: Output Buffers, Sept 2005
...Sort of,...well, OK,...it's resolved,... :dazzled:
Zen

jj2007

"the content of an output item, after a call has failed /absolutely/" (last post in Raymond Chen's log)

I usually try to return a short printable string on failure, like a single question mark, or "La$?" in the case of Launch$(); in the case of GetRegVal, you can specify a default string, or zero. No default string means in this case "throw an error".

@Tedd: I have difficulties to see how the same identical code could treat a number sometimes as signed, sometimes as unsigned...

Magnum

Quote from: Tedd on August 28, 2013, 12:16:04 AM
A quick guess would be the value is sometimes treated as unsigned and others as signed; so, "-1" would be 4294967295 or -1 -- indicating a huge buffer, or none at all (negative size.) If this is the case, you could probably get away with using 2147483647 (7FFFFFFh) as the largest signed value; though some functions may have been ported directly from their original 16-bit ini-file versions and cause further problems, naturally.

Anyway, if you know your buffer size is 'big enough' why not just pass its size straight in? You should already know its size if you know it's big enough.
If you're only expecting a 20 byte string, why say the buffer is any larger? And if it turns out to be larger, that actually should cause an error because it's an unexpected situation that you're not explicitly handling, which will eventually lead to difficult bugs elsewhere.

This is just corner-cutting for the sake of laziness -- do it right or it will (and should) bite you eventually.

Tedd,

I do not understand what you mean by saying the buffer is any larger.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Tedd

Quote from: jj2007 on August 28, 2013, 07:01:57 AM
@Tedd: I have difficulties to see how the same identical code could treat a number sometimes as signed, sometimes as unsigned...
If it's always the same function call, then obviously not; like I said, it was just a quick guess.



Quote from: Magnum on August 28, 2013, 11:51:36 AM
I do not understand what you mean by saying the buffer is any larger.
"If you're only expecting a 20 byte string, why say the buffer is some arbitrary amount larger?"
Potato2