For Programmers: Free Programming Magazines  


Home > Archive > Smartphone Developer Forum > January 2006 > MSDN vs. eVC4 wizard, who's right this time?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author MSDN vs. eVC4 wizard, who's right this time?
Norman Diamond

2006-01-23, 4:00 am

Thanks to Riki-san for answering three of my questions last w, two of
which involved a wizard in eVC++4 producing code that relies on behaviour
undocumented in MSDN and/or conflicts with instructions in MSDN. In those
two cases, the answer to one was to rely on Microsoft's code instead of
Microsoft's documentation, and the answer to the other one was to rely on
Microsoft's documentation instead of Microsoft's code.

Now here's another one, and I can't guess which to rely on. I estimate
there's a 33% chance that Microsoft's code is right, 33% that Microsoft's
documentation is right, and 34% that neither is right.

MSDN is almost clear enough. Page
http://msdn.microsoft.com/library/d...fLoadString.asp
says:
> Return Values
> The number of characters copied into the buffer, excluding the terminating
> null character, indicates success. Zero indicates that the string resource
> does not exist. To get extended error information, call GetLastError.


If zero is the number of characters copied into the buffer, excluding the
terminating null character, then zero indicates success. Zero also
indicates a form of failure. So to distinguish which kind of zero this is,
we have to call GetLastError.

Page
http://msdn.microsoft.com/library/d...etlasterror.asp
says:
> [...] some functions call SetLastError(0) when they succeed, wiping out
> the error code set by the most recently failed function.


Right. We don't know whether or not LoadString calls SetLastError(0) when
it succeeds, we only know that there's a possibility. We do know that
LoadString calls SetLastError with some nonzero value when it fails. So in
order to use GetLastError to check whether LoadString's zero return was a
success zero or a failure zero, we need this code:
// Get our message text.
SetLastError(0);
if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
ARRAYSIZE(g_szMessage))) {
if(0 != GetLastError()) {
// Couldn't load the string. Fail creation of the window.
return(-1);
}
}

But the wizard didn't do that. The wizard generated this code:
// Get our message text.
if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
ARRAYSIZE(g_szMessage))) {
// Couldn't load the string. Fail creation of the window.
return(-1);
}

So which is right, MSDN or the wizard?

Or maybe neither? Let's look at LoadString again. It returns int. Can the
return value ever be negative? What happens if some error occurs other than
nonexistence of the string resource, then the return value can't be either
zero or positive ... or can zero have a third meaning ..... Anyway, should
we check for negative returns? The wizard didn't. The code says that a
negative return (if it's possible) was a success.

Now for an unrelated question about LoadString. MSDN says:
> To use the lpBuffer pointer, the ?n flag must be set with the resource
> compiler, RC.


I didn't check if eVC++4 SP4 defaulted to putting the ?n flag in the
project. If it didn't, then where does the string get loaded into instead
of the memory pointed to by the lpBuffer pointer?

Michael J. Salamone

2006-01-23, 4:00 am

You can get a definitive answer in the MS Shared Source for WinCE.

If you have it installed, go to
WINCEXXX\PRIVATE\WINCEOS\COREOS\NK\KERNE
L\resource.c.

If you don't have it installed, it's definitely worth getting it.

My hunch on this one is that MSDN is correct. But I leave it as an
excercise to the reader to verify it by either 1) checking the shared source
code or 2) writing test cases that you can use to determine the behavior.

--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com


"Norman Diamond" <ndiamond@community.nospam> wrote in message
news:%23NkD8z9HGHA.648@TK2MSFTNGP14.phx.gbl...
> Thanks to Riki-san for answering three of my questions last w, two of
> which involved a wizard in eVC++4 producing code that relies on behaviour
> undocumented in MSDN and/or conflicts with instructions in MSDN. In those
> two cases, the answer to one was to rely on Microsoft's code instead of
> Microsoft's documentation, and the answer to the other one was to rely on
> Microsoft's documentation instead of Microsoft's code.
>
> Now here's another one, and I can't guess which to rely on. I estimate
> there's a 33% chance that Microsoft's code is right, 33% that Microsoft's
> documentation is right, and 34% that neither is right.
>
> MSDN is almost clear enough. Page
> http://msdn.microsoft.com/library/d...fLoadString.asp
> says:
>
> If zero is the number of characters copied into the buffer, excluding the
> terminating null character, then zero indicates success. Zero also
> indicates a form of failure. So to distinguish which kind of zero this
> is,
> we have to call GetLastError.
>
> Page
> http://msdn.microsoft.com/library/d...etlasterror.asp
> says:
>
> Right. We don't know whether or not LoadString calls SetLastError(0) when
> it succeeds, we only know that there's a possibility. We do know that
> LoadString calls SetLastError with some nonzero value when it fails. So
> in
> order to use GetLastError to check whether LoadString's zero return was a
> success zero or a failure zero, we need this code:
> // Get our message text.
> SetLastError(0);
> if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
> ARRAYSIZE(g_szMessage))) {
> if(0 != GetLastError()) {
> // Couldn't load the string. Fail creation of the window.
> return(-1);
> }
> }
>
> But the wizard didn't do that. The wizard generated this code:
> // Get our message text.
> if(0 == LoadString(g_hInst, IDS_HELLO_MESSAGE, g_szMessage,
> ARRAYSIZE(g_szMessage))) {
> // Couldn't load the string. Fail creation of the window.
> return(-1);
> }
>
> So which is right, MSDN or the wizard?
>
> Or maybe neither? Let's look at LoadString again. It returns int. Can
> the
> return value ever be negative? What happens if some error occurs other
> than
> nonexistence of the string resource, then the return value can't be either
> zero or positive ... or can zero have a third meaning ..... Anyway,
> should
> we check for negative returns? The wizard didn't. The code says that a
> negative return (if it's possible) was a success.
>
> Now for an unrelated question about LoadString. MSDN says:
>
> I didn't check if eVC++4 SP4 defaulted to putting the ?n flag in the
> project. If it didn't, then where does the string get loaded into instead
> of the memory pointed to by the lpBuffer pointer?
>



Norman Diamond

2006-01-23, 4:00 am

OK, for the moment I'm writing code assuming that MSDN is correct. I didn't
do much yet but so far it's working. Thank you.

Yeah, no kidding that we can write test cases to try to figure out whether
MSDN is correct. At peak times I have to waste time doing that more than
once per day.

The rules for shared source aren't completely clear, but one thing that does
seem clear is that we don't qualify. Our customer does licence more than
50,000 Windows CE runtimes each year, but we don't. We make software
(mostly on contracts to OEMs) and we make small lots of hardware (sometimes
prototypes and sometimes small production runs for OEMs). For Windows CE 5
the requirement is reduced to 5,000 per year, but we don't meet that either,
and anyway our customer is still expecting us to target CE 4.2. It looks
like a 120-day evaluation kit for some tool set might be able to get us the
shared source even when we don't qualify for it. I'm wondering whether to
try when we don't qualify for it.


"Michael J. Salamone" <mikesa#at#entrek#dot#com> wrote in message
news:ep9UZK%23HGHA.3728@tk2msftngp13.phx.gbl...
> You can get a definitive answer in the MS Shared Source for WinCE.
>
> If you have it installed, go to
> WINCEXXX\PRIVATE\WINCEOS\COREOS\NK\KERNE
L\resource.c.
>
> If you don't have it installed, it's definitely worth getting it.
>
> My hunch on this one is that MSDN is correct. But I leave it as an
> excercise to the reader to verify it by either 1) checking the shared
> source code or 2) writing test cases that you can use to determine the
> behavior.
>
> --
> Michael Salamone [eMVP]
> Entrek Software, Inc.
> www.entrek.com
>
>
> "Norman Diamond" <ndiamond@community.nospam> wrote in message
> news:%23NkD8z9HGHA.648@TK2MSFTNGP14.phx.gbl...
>
>


riki

2006-01-23, 7:06 pm

Norman Diamond wrote:
> OK, for the moment I'm writing code assuming that MSDN is correct. I
> didn't do much yet but so far it's working. Thank you.
>
> Yeah, no kidding that we can write test cases to try to figure out
> whether MSDN is correct. At peak times I have to waste time doing that
> more than once per day.
>
> The rules for shared source aren't completely clear, but one thing that
> does seem clear is that we don't qualify. Our customer does licence
> more than 50,000 Windows CE runtimes each year, but we don't. We make
> software (mostly on contracts to OEMs) and we make small lots of
> hardware (sometimes prototypes and sometimes small production runs for
> OEMs). For Windows CE 5 the requirement is reduced to 5,000 per year,
> but we don't meet that either, and anyway our customer is still
> expecting us to target CE 4.2. It looks like a 120-day evaluation kit
> for some tool set might be able to get us the shared source even when we
> don't qualify for it. I'm wondering whether to try when we don't
> qualify for it.

the eval is free to use, you don't need to qualify with specific volumes.

My reading of that function: it calls SetLastError(
ERROR_INVALID_PARAMETER); if the params are invalid or there is an
exception. it looks like it will return 0 for both 0 length strings and
failure to find the string.

hmm

looking into FindResource() which LoadString() calls, it seems that it
will call SetLastError(ERROR_RESOURCE_NAME_NOT_FOU
ND); if it fails. does
that help?

riki

So, the key to a successful cow-tipping operation is as follows: attack
before you hit the pub, go mob-handed and in stealth mode. Then, clear
your mind of Newtonian impediments to unhoofing your chosen target
before launching a Ninja-style co-ordinated assault. - TheRegister.co.uk
By Night:
ThemeChanger for Smartphone : http://homepages.inspire.net.nz/~gambit/
AbstractStart for Smartphone :
http://homepages.inspire.net.nz/~gambit/AbstractStart/
Latest Betas have WM5 layout and speed dial support
Norman Diamond

2006-01-23, 7:06 pm

"riki" <see_my_home@page> wrote in message
news:uqATLEGIGHA.1728@TK2MSFTNGP09.phx.gbl...

> the eval is free to use, you don't need to qualify with specific volumes.


Thank you. I'll look at it again.

> it looks like it will return 0 for both 0 length strings and failure to
> find the string.


So this time MSDN is right and eVC++4's wizard is wrong.

I'm calling SetLastError(0) before LoadString, and if LoadString returns 0
then I'm calling GetLastError() to see if the error code has changed to
nonzero.

> looking into FindResource() which LoadString() calls


Umm, so FindResource works sometimes? Any chance you might be able to help
with two other questions I posted yesterday? I can't figure out how to make
FindResource work.

riki

2006-01-24, 3:59 am

Norman Diamond wrote:
> Umm, so FindResource works sometimes? Any chance you might be able to help
> with two other questions I posted yesterday? I can't figure out how to
> make
> FindResource work.


I'll have a look through tomorrow, and see if i can get you an answer :-)

riki



"All men are mortal. Socrates was mortal. Therefore, all men are
Socrates." -- Woody Allen
ThemeChanger for Smartphone : http://homepages.inspire.net.nz/~gambit/
AbstractStart for Smartphone :
http://homepages.inspire.net.nz/~gambit/AbstractStart/
Latest Betas have WM5 layout and speed dial support
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com