Solved

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

Posted on 2006-07-03
8
495 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now