Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetLastError only returns B7

714 views
Skip to first unread message

jayMFC

unread,
May 13, 2009, 4:29:02 AM5/13/09
to
I notice that every time I use GetLastError function to find out what has
gone wrong in my code it seems to only be returning error code 183 (0xB7)
ERROR_ALREADY_EXISTS, “Cannot create a file when that file already exists.”
However the API I am calling has nothing to do with file creation. Examples
of the API I have recently reviewed are IsIconic and GetModuleFileNameEx.

I am really confused by these findings. Please if anybody has any
suggestions or comments on these findings it would be greatly appreciated.

Goran

unread,
May 13, 2009, 7:12:20 AM5/13/09
to
Pics or it doesn't happen ;-)

Are you sure that you are doing exactly this all the time:

if (!CallAPI())
{
DWORD dwError = GetLastError();
DoStuffWith(dwError);
}

If you are doing anything else, however similar, you are doing it
wrong. GetLastError is only reliable for a given API after the call to
this API failed (only in rare circumstances it may be valid after a
success, and this is normally noted in MSDN and most likely not your
case).

Goran.

jayMFC

unread,
May 13, 2009, 8:59:01 AM5/13/09
to
Yes I am calling the GetLastError function immediately after I call the API
function. This is why I am confused about the error code I am receiving

Goran

unread,
May 13, 2009, 9:40:05 AM5/13/09
to
> Yes I am calling the GetLastError function
> immediately after I call the API function.

Did API fail? If not, GetLastError ain't good.

jayMFC

unread,
May 14, 2009, 3:58:01 AM5/14/09
to
This how I get the error code

if(CallAPI())
{
Do what needs to be done
}
else
{
DWORD dw = GetLastError();
printf(" CallAPI failed, the error code is %X", dw);

jayMFC

unread,
May 14, 2009, 5:51:01 AM5/14/09
to
This how I get the error code

if(CallAPI())
{
Do what needs to be done
}
else
{
DWORD dw = GetLastError();
printf(" CallAPI failed, the error code is %X", dw);

SvenC

unread,
May 14, 2009, 7:33:03 AM5/14/09
to
Hi jayMFC,

> This how I get the error code
>
> if(CallAPI())
> {
> Do what needs to be done
> }
> else
> {
> DWORD dw = GetLastError();
> printf(" CallAPI failed, the error code is %X", dw);
> }

Is CallAPI a Win32 function or your function?

Can you really reproduce your problem in a minimal
sample? Just main or WinMain with your fsiling API-Call and
GetLastError returning an incorrect error.

--
SvenC

Stephen Myers

unread,
May 14, 2009, 12:52:13 PM5/14/09
to

The key is what happens within CallAPI() especially after it determines
that there is a failure. It is easy enough to do something in the
internal error handling which would in turn result in the 0xB7 error
code. Something as simple as opening a log file to write status info
would do it.

So again, what is CallAPI()?

Steve

Joseph M. Newcomer

unread,
May 17, 2009, 5:25:48 PM5/17/09
to
I'm also curious why the error code is being displayed in hex when the error file
expresses most error codes in decimal. Hex is nearly useless. If you want to do
anything, you should do

_tprintf(_T(" CallAPI failed, the error code is %d (0x%08x)"), dw, dw);

Note that you are using the placeholder CallAPI to represent an API that has a BOOL return
value. It would be a lot easier to tell what is going on if you showed us the actual API
you called, with the actual parameters you used, instead of just showing us an abstract
example.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages