Solved

GetFullPathName returns zero and cannot use GetLastError to get the error info

Posted on 2006-07-03
8
498 Views
Last Modified: 2013-12-03
I try to call GetFullPathName as follows:

      CString s;
      int nError;

      CString strPath;
      TCHAR lpszPathOut[1024];
      LPSTR lpszFilePart;

      strPath = _T("J:\\BackupYme_recovered\\Sett opprettet 28.03.2006 kl. 12_53\\Lokal disk\\Documents and Settings\\Stein Inge Haaland\\Lokale innstillinger\\Temporary Internet Files\\Content.IE5\\0LWRG34N\\1305882082@x01,x04,Right2,Right3,x05,x06,Middle3,Middle2,Bottom3,Bottom1,Top3,Top");
      if (!GetFullPathName(strPath, MAX_PATH, lpszPathOut, &lpszFilePart))      {
            nError = GetLastError();
            TRACE(_T("Last error: %d.\r\n"), nError);
      }

GetFullPathName returns 0. But GetLastError also returns 0. Therefore, I cannot determine the reason why GetFullPathName fails. Please help me.
0
Comment
Question by:chcw
8 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 17035135
I have a feeling it worked but the file does not exist. I notice your using CString from MFC why dont you try using CFileFInd

example:


CFileFind File;
CString FilePath;

File.FindFile("J:\\BackupYme_recovered\\Sett opprettet 28.03.2006 kl. 12_53\\Lokal disk\\Documents and Settings\\Stein Inge Haaland\\Lokale innstillinger\\Temporary Internet Files\\Content.IE5\\0LWRG34N\\1305882082@x01,x04,Right2,Right3,x05,x06,Middle3,Middle2,Bottom3,Bottom1,Top3,Top");

File.FileFindNext();   // you must call this to use the other file functions.

FilePath = File.GetFilePath();

0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 17035143
you could also try using GetLongPathName() since the path is rather long
0
 
LVL 8

Author Comment

by:chcw
ID: 17035304
I try to use CFile to create the file, and in the source codes of CFile, there is a statement calling GetFullPathName, just similar to the codes we mentioned above.
0
 
LVL 8

Accepted Solution

by:
mxjijo earned 500 total points
ID: 17054193

Just an observation..

The file name length is equal to MAX_PATH (which is 260)
When I did a character count, it gives me 261.
May be its a good idea to create a file with sligthly lesser number of chars in the name and try out your code.

Also you may use filemon.exe (sysinternals.com) to see the status of the call you make.

~j
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17055326
How about allowing GetFullPathName the full buffer length of 1024 (-1)

 CString strPath;
 TCHAR lpszPathOut[1024];
  LPSTR lpszFilePart;

     strPath = _T("J:\\BackupYme_recovered\\Sett opprettet 28.03.2006 kl. 12_53\\Lokal disk\\Documents and Settings\\Stein Inge Haaland\\Lokale innstillinger\\Temporary Internet Files\\Content.IE5\\0LWRG34N\\1305882082@x01,x04,Right2,Right3,x05,x06,Middle3,Middle2,Bottom3,Bottom1,Top3,Top");
     
  //** 1023 instead of MAX_PATH
  if (!GetFullPathName(strPath, 1023, lpszPathOut, &lpszFilePart))     {
          nError = GetLastError();
          TRACE(_T("Last error: %d.\r\n"), nError);

Cheers,
Sebastian
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now