🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #869

Re: Cannot retrieve file date

#869
From: Ed Mulroy [TeamB]
Date: Wed, 02 Jan 2008 22:11
82 lines
3223 bytes
Here is a working function that uses FormatMessage to display what the 
problem reported by GetLastError is:

---------------------------
// hwnd - the parent window, use NULL if there is none
// title_text - the text that will show in the title of an error
//
//  message box.  Use "" or NULL if you do not want to
//  provide any text
//
// If GetLastError() returns zero, indicating no error, no
// error message is shown
//
// This function returns the last error number and sets
// last error in the OS to zero
//
DWORD WINAPI ShowLastError(HWND hwnd, const char *title_text)
  {
  TCHAR *err_msg;
  DWORD last_error = GetLastError();

  FormatMessage(
      FORMAT_MESSAGE_ALLOCATE_BUFFER |
          FORMAT_MESSAGE_FROM_SYSTEM,
      NULL,
      last_error,
      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
      reinterpret_cast<LPTSTR>(&err_msg),
      0,
      NULL);

  if (title_text && *title_text)
    MessageBox(hwnd, err_msg, title_text, MB_OK);
  else
    MessageBox(hwnd, err_msg, "Error", MB_OK);

  LocalFree(err_msg);
  SetLastError(0);
  return last_error;
  }

---------------------------

.  Ed

> Jos� wrote in message
> news:hfonn3l8o175ht0j11i9d4q5msanpr6apt@4ax.com...
>
> What went wrong?
>
> _FILETIME f1;
>  FILE*han1=fopen("J:\\Projects\\test1.h","r");
>  res=GetFileTime(han1,  &f1,NULL,NULL);
>
> The file exists, han1 is not zero and the file can be read. But
> GetFileTime returns an error.
>
> I tried to find what went wrong. The help file tells me to:
>
> LPVOID lpMsgBuf;
>
> But that causes a compilation error, ("cannot convert void * to const
> char *) so I declared:
>
> char* lpMsgBuf;
>
> and it goes on:
>
> FormatMessage(
>    FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
>    NULL,     GetLastError(),
>    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
>    (LPTSTR) &lpMsgBuf,     0,      NULL);
> MessageBox( NULL, lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION);
> LocalFree( lpMsgBuf );
>
> The error message is "De ingang is ongeldig". If I set the language to
> English, no message is returned. Translated into English, it would be
> "The entry is invalid".
>
> Well, that's good to know: the entry is invalid! But what is the
> entry? And why is it invalid?
Technical Details
Message-ID: <477c0c06$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <hfonn3l8o175ht0j11i9d4q5msanpr6apt@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4011bf1b28cc5925
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII
From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <hfonn3l8o175ht0j11i9d4q5msanpr6apt@4ax.com>
Subject: Re: Cannot retrieve file date
Date: Wed, 2 Jan 2008 17:11:12 -0500
Lines: 84
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 71.77.53.190
Message-ID: <477c0c06$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1199311878 71.77.53.190 (2 Jan 2008 14:11:18 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail