Solved

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

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

636 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