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. SearchPath API fails in UNICODE debug build

SearchPath API fails in UNICODE debug build

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncementdebuggingjsonquestion
4 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.
  • V Offline
    V Offline
    Vinaya
    wrote on last edited by
    #1

    Hi, My application calls the SearchPath() API in a method which gets the version info of a file. On execution, the UNICODE debug version of the application always crashes. The error shown is 'Unhandled exception in MyAppl.exe (NTDLL.DLL): 0xC0000005: Access Violation'. The MBCS/UNICODE Release build of the application works fine and also the MBCS debug build. DI_STATUS getFileVersionInfo(TCHAR * FileName) { TCHAR pathBuffer[MAX_PATH]; struct VS_FIXEDFILEINFO { DWORD dwSignature; DWORD dwStrucVersion; DWORD dwFileVersionMS; DWORD dwFileVersionLS; DWORD dwProductVersionMS; DWORD dwProductVersionLS; DWORD dwFileFlagsMask; DWORD dwFileFlags; DWORD dwFileOS; DWORD dwFileType; DWORD dwFileSubtype; DWORD dwFileDateMS; DWORD dwFileDateLS; } *lpFixedFileInfo; TCHAR fileInfoBuffer[2048]; UINT32 VersionInfoSize; if (SearchPath(NULL, FileName, NULL, sizeof(pathBuffer), pathBuffer, NULL) > 0) { LogMsg(_T(" SearchPath: %s\n"), pathBuffer); } else { return(ERR_FILE_NOT_FOUND); } if ((VersionInfoSize = GetFileVersionInfoSize(FileName, 0)) > 0) { if (GetFileVersionInfo(FileName, NULL, VersionInfoSize, fileInfoBuffer) > 0) { VerQueryValue(fileInfoBuffer, TEXT("\\"), (LPVOID *)&lpFixedFileInfo, &VersionInfoSize); LogMsg(_T(" FileName : %s Version: %d.%d.%d.%d\n"),FileName, HIWORD(lpFixedFileInfo->dwFileVersionMS), LOWORD(lpFixedFileInfo->dwFileVersionMS), HIWORD(lpFixedFileInfo->dwFileVersionLS), LOWORD(lpFixedFileInfo->dwFileVersionLS)); } else { return(DI_ERR_FILE_NOT_FOUND); } } else { return(ERR_FILE_NOT_FOUND); } return(DI_SUCCESS); } The function call is

    TCHAR tmp[1024];
    GetModuleFileName(NULL, tmp, sizeof(tmp));
    getFileVersionInfo(tmp);
    

    Am I missing out something here? I have Win2K OS. Please help. Thanks, Vini

    R R 2 Replies Last reply
    0
    • V Vinaya

      Hi, My application calls the SearchPath() API in a method which gets the version info of a file. On execution, the UNICODE debug version of the application always crashes. The error shown is 'Unhandled exception in MyAppl.exe (NTDLL.DLL): 0xC0000005: Access Violation'. The MBCS/UNICODE Release build of the application works fine and also the MBCS debug build. DI_STATUS getFileVersionInfo(TCHAR * FileName) { TCHAR pathBuffer[MAX_PATH]; struct VS_FIXEDFILEINFO { DWORD dwSignature; DWORD dwStrucVersion; DWORD dwFileVersionMS; DWORD dwFileVersionLS; DWORD dwProductVersionMS; DWORD dwProductVersionLS; DWORD dwFileFlagsMask; DWORD dwFileFlags; DWORD dwFileOS; DWORD dwFileType; DWORD dwFileSubtype; DWORD dwFileDateMS; DWORD dwFileDateLS; } *lpFixedFileInfo; TCHAR fileInfoBuffer[2048]; UINT32 VersionInfoSize; if (SearchPath(NULL, FileName, NULL, sizeof(pathBuffer), pathBuffer, NULL) > 0) { LogMsg(_T(" SearchPath: %s\n"), pathBuffer); } else { return(ERR_FILE_NOT_FOUND); } if ((VersionInfoSize = GetFileVersionInfoSize(FileName, 0)) > 0) { if (GetFileVersionInfo(FileName, NULL, VersionInfoSize, fileInfoBuffer) > 0) { VerQueryValue(fileInfoBuffer, TEXT("\\"), (LPVOID *)&lpFixedFileInfo, &VersionInfoSize); LogMsg(_T(" FileName : %s Version: %d.%d.%d.%d\n"),FileName, HIWORD(lpFixedFileInfo->dwFileVersionMS), LOWORD(lpFixedFileInfo->dwFileVersionMS), HIWORD(lpFixedFileInfo->dwFileVersionLS), LOWORD(lpFixedFileInfo->dwFileVersionLS)); } else { return(DI_ERR_FILE_NOT_FOUND); } } else { return(ERR_FILE_NOT_FOUND); } return(DI_SUCCESS); } The function call is

      TCHAR tmp[1024];
      GetModuleFileName(NULL, tmp, sizeof(tmp));
      getFileVersionInfo(tmp);
      

      Am I missing out something here? I have Win2K OS. Please help. Thanks, Vini

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      Vinaya wrote: GetModuleFileName(NULL, tmp, sizeof(tmp)); The third parameter is the number of characters, not the size of the buffer in bytes. You'll need to pass in 1024 to indicate there are 1024 characters (or sizeof(tmp)/sizeo(TCHAR)) Vinaya wrote: SearchPath(NULL, FileName, NULL, sizeof(pathBuffer), pathBuffer, NULL) Ditto for the fourth parameter here.

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      1 Reply Last reply
      0
      • V Vinaya

        Hi, My application calls the SearchPath() API in a method which gets the version info of a file. On execution, the UNICODE debug version of the application always crashes. The error shown is 'Unhandled exception in MyAppl.exe (NTDLL.DLL): 0xC0000005: Access Violation'. The MBCS/UNICODE Release build of the application works fine and also the MBCS debug build. DI_STATUS getFileVersionInfo(TCHAR * FileName) { TCHAR pathBuffer[MAX_PATH]; struct VS_FIXEDFILEINFO { DWORD dwSignature; DWORD dwStrucVersion; DWORD dwFileVersionMS; DWORD dwFileVersionLS; DWORD dwProductVersionMS; DWORD dwProductVersionLS; DWORD dwFileFlagsMask; DWORD dwFileFlags; DWORD dwFileOS; DWORD dwFileType; DWORD dwFileSubtype; DWORD dwFileDateMS; DWORD dwFileDateLS; } *lpFixedFileInfo; TCHAR fileInfoBuffer[2048]; UINT32 VersionInfoSize; if (SearchPath(NULL, FileName, NULL, sizeof(pathBuffer), pathBuffer, NULL) > 0) { LogMsg(_T(" SearchPath: %s\n"), pathBuffer); } else { return(ERR_FILE_NOT_FOUND); } if ((VersionInfoSize = GetFileVersionInfoSize(FileName, 0)) > 0) { if (GetFileVersionInfo(FileName, NULL, VersionInfoSize, fileInfoBuffer) > 0) { VerQueryValue(fileInfoBuffer, TEXT("\\"), (LPVOID *)&lpFixedFileInfo, &VersionInfoSize); LogMsg(_T(" FileName : %s Version: %d.%d.%d.%d\n"),FileName, HIWORD(lpFixedFileInfo->dwFileVersionMS), LOWORD(lpFixedFileInfo->dwFileVersionMS), HIWORD(lpFixedFileInfo->dwFileVersionLS), LOWORD(lpFixedFileInfo->dwFileVersionLS)); } else { return(DI_ERR_FILE_NOT_FOUND); } } else { return(ERR_FILE_NOT_FOUND); } return(DI_SUCCESS); } The function call is

        TCHAR tmp[1024];
        GetModuleFileName(NULL, tmp, sizeof(tmp));
        getFileVersionInfo(tmp);
        

        Am I missing out something here? I have Win2K OS. Please help. Thanks, Vini

        R Offline
        R Offline
        RChin
        wrote on last edited by
        #3

        Vinaya wrote: if (SearchPath(NULL, FileName, NULL, sizeof(pathBuffer), pathBuffer, NULL) > 0) Your exception is basically caused by the sizeof() input parameter of the function. This parameter required the number of characters that your string buffer holds. But the sizeof() function returns the number of bytes within the array. With a UNICODE program, each character occupies two bytes, so will therefore return twice the number required, resulting in a memory exception. Try: if (SearchPath(NULL, FileName, NULL, sizeof(pathBuffer)/sizeof(TCHAR), pathBuffer, NULL) > 0)


        I Dream of Absolute Zero

        V 1 Reply Last reply
        0
        • R RChin

          Vinaya wrote: if (SearchPath(NULL, FileName, NULL, sizeof(pathBuffer), pathBuffer, NULL) > 0) Your exception is basically caused by the sizeof() input parameter of the function. This parameter required the number of characters that your string buffer holds. But the sizeof() function returns the number of bytes within the array. With a UNICODE program, each character occupies two bytes, so will therefore return twice the number required, resulting in a memory exception. Try: if (SearchPath(NULL, FileName, NULL, sizeof(pathBuffer)/sizeof(TCHAR), pathBuffer, NULL) > 0)


          I Dream of Absolute Zero

          V Offline
          V Offline
          Vinaya
          wrote on last edited by
          #4

          Thanks a lot. :rose: That solved the problem. :) Vini

          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