Solved

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

Posted on 2006-07-03
8
486 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
Comment Utility
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
Comment Utility
you could also try using GetLongPathName() since the path is rather long
0
 
LVL 8

Author Comment

by:chcw
Comment Utility
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
Comment Utility

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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

7 Experts available now in Live!

Get 1:1 Help Now