Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. OutPutDebugStringW Issue

OutPutDebugStringW Issue

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gothic_coder
    wrote on last edited by
    #1

    Hello all, I'm trying to print the filename to Dbgview which i receive from GetFileInformationByHandleEx, But it's getting crashed every time..

    PFILE_NAME_INFO pFileNameInfo;
    DWORD dwFileNameLength = 1024;
    DWORD err;
    TCHAR szTemp[MAX_PATH] = "";

    pFileNameInfo = (PFILE_NAME_INFO)HeapAlloc(GetProcessHeap(), 0, dwFileNameLength);

    if(pFileNameInfo != NULL)
    {
    if(GetFileInformationByHandleEx(FileHandle, FileNameInfo, &pFileNameInfo, dwFileNameLength) != 0)
    {
    MessageBox(NULL, L"Before Check", L"Success", MB_OK);
    OutputDebugStringW(pFileNameInfo->FileName);
    }
    else
    {
    err = GetLastError();
    swprintf(szTemp, L"Get info Error = %d", err);
    MessageBox(NULL, szTemp, L"Error", MB_OK);
    }
    HeapFree(GetProcessHeap(), 0, pFileNameInfo);
    }
    else
    {
    err = GetLastError();
    swprintf(szTemp, L"Heap Error = %d", err);
    MessageBox(NULL, szTemp, L"Error", MB_OK);
    }

    Thanks All..

    I L 2 Replies Last reply
    0
    • G gothic_coder

      Hello all, I'm trying to print the filename to Dbgview which i receive from GetFileInformationByHandleEx, But it's getting crashed every time..

      PFILE_NAME_INFO pFileNameInfo;
      DWORD dwFileNameLength = 1024;
      DWORD err;
      TCHAR szTemp[MAX_PATH] = "";

      pFileNameInfo = (PFILE_NAME_INFO)HeapAlloc(GetProcessHeap(), 0, dwFileNameLength);

      if(pFileNameInfo != NULL)
      {
      if(GetFileInformationByHandleEx(FileHandle, FileNameInfo, &pFileNameInfo, dwFileNameLength) != 0)
      {
      MessageBox(NULL, L"Before Check", L"Success", MB_OK);
      OutputDebugStringW(pFileNameInfo->FileName);
      }
      else
      {
      err = GetLastError();
      swprintf(szTemp, L"Get info Error = %d", err);
      MessageBox(NULL, szTemp, L"Error", MB_OK);
      }
      HeapFree(GetProcessHeap(), 0, pFileNameInfo);
      }
      else
      {
      err = GetLastError();
      swprintf(szTemp, L"Heap Error = %d", err);
      MessageBox(NULL, szTemp, L"Error", MB_OK);
      }

      Thanks All..

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      Have you tried single stepping? Do you end up with a filename which should be NULL terminated, but is not? If it's crashing all the time, it sounds simple to find with a debugger! If nothing else, you'll know WHICH line is crashing. Have you tried with a small filename? Iain.

      I am one of "those foreigners coming over here and stealing our jobs". Yay me!

      1 Reply Last reply
      0
      • G gothic_coder

        Hello all, I'm trying to print the filename to Dbgview which i receive from GetFileInformationByHandleEx, But it's getting crashed every time..

        PFILE_NAME_INFO pFileNameInfo;
        DWORD dwFileNameLength = 1024;
        DWORD err;
        TCHAR szTemp[MAX_PATH] = "";

        pFileNameInfo = (PFILE_NAME_INFO)HeapAlloc(GetProcessHeap(), 0, dwFileNameLength);

        if(pFileNameInfo != NULL)
        {
        if(GetFileInformationByHandleEx(FileHandle, FileNameInfo, &pFileNameInfo, dwFileNameLength) != 0)
        {
        MessageBox(NULL, L"Before Check", L"Success", MB_OK);
        OutputDebugStringW(pFileNameInfo->FileName);
        }
        else
        {
        err = GetLastError();
        swprintf(szTemp, L"Get info Error = %d", err);
        MessageBox(NULL, szTemp, L"Error", MB_OK);
        }
        HeapFree(GetProcessHeap(), 0, pFileNameInfo);
        }
        else
        {
        err = GetLastError();
        swprintf(szTemp, L"Heap Error = %d", err);
        MessageBox(NULL, szTemp, L"Error", MB_OK);
        }

        Thanks All..

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You are sending the address of your memory pointer rather than the pointer itself to the GetFileInformationByHandleEx() function. The code should read:

        if (GetFileInformationByHandleEx(FileHandle, FileNameInfo, pFileNameInfo, dwFileNameLength) != 0)
        

        Note: no & (addressof operator) on pFileNameInfo.

        It's time for a new signature.

        G 1 Reply Last reply
        0
        • L Lost User

          You are sending the address of your memory pointer rather than the pointer itself to the GetFileInformationByHandleEx() function. The code should read:

          if (GetFileInformationByHandleEx(FileHandle, FileNameInfo, pFileNameInfo, dwFileNameLength) != 0)
          

          Note: no & (addressof operator) on pFileNameInfo.

          It's time for a new signature.

          G Offline
          G Offline
          gothic_coder
          wrote on last edited by
          #4

          Yes, Silly Mistake, There shouldn't be &.. Thanks Also how do i get the real path? pFileInfo->FileName gives me "\sample\a.txt"and i need "C:\sample\a.txt"

          L 1 Reply Last reply
          0
          • G gothic_coder

            Yes, Silly Mistake, There shouldn't be &.. Thanks Also how do i get the real path? pFileInfo->FileName gives me "\sample\a.txt"and i need "C:\sample\a.txt"

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            gothic_coder wrote:

            how do i get the real path?

            I'm not sure offhand, I would suggest checking the MSDN documentation for this function and seeing if it has any links to other similar functions.

            It's time for a new signature.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups