Solved

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

Posted on 2006-07-03
8
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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