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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetModuleFileName returning blank!

GetModuleFileName returning blank!

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingannouncementquestionworkspace
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.
  • N Offline
    N Offline
    ns
    wrote on last edited by
    #1

    I am running in the debugger and find that sPath = "" !!

    VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, \_MAX\_PATH));
    
    sPath = (CString)szBuffer; //sPath returns blank!
    sPath = sPath.Left(sPath.ReverseFind('\\\\'));	
    

    What am I doing wrong? Many thanks, ns I just found out that I get the sPath if I run the debug config, butr I have setup my release config to allow debugging too, and when that version runs I get blank!

    J 1 Reply Last reply
    0
    • N ns

      I am running in the debugger and find that sPath = "" !!

      VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, \_MAX\_PATH));
      
      sPath = (CString)szBuffer; //sPath returns blank!
      sPath = sPath.Left(sPath.ReverseFind('\\\\'));	
      

      What am I doing wrong? Many thanks, ns I just found out that I get the sPath if I run the debug config, butr I have setup my release config to allow debugging too, and when that version runs I get blank!

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      For me, these lines

      CString filenname;
      ::GetModuleFileName(AfxGetApp()->m_hInstance, filenname.GetBuffer(MAX_PATH+1), MAX_PATH);
      filenname.ReleaseBuffer();

      do work. You might want to check the return-code and GetLastErr() of GetModuleFileName.


      Who is 'General Failure'? And why is he reading my harddisk?!?

      N M 2 Replies Last reply
      0
      • J jhwurmbach

        For me, these lines

        CString filenname;
        ::GetModuleFileName(AfxGetApp()->m_hInstance, filenname.GetBuffer(MAX_PATH+1), MAX_PATH);
        filenname.ReleaseBuffer();

        do work. You might want to check the return-code and GetLastErr() of GetModuleFileName.


        Who is 'General Failure'? And why is he reading my harddisk?!?

        N Offline
        N Offline
        ns
        wrote on last edited by
        #3

        I hadnt set up the prj correctly for debugging

        1 Reply Last reply
        0
        • J jhwurmbach

          For me, these lines

          CString filenname;
          ::GetModuleFileName(AfxGetApp()->m_hInstance, filenname.GetBuffer(MAX_PATH+1), MAX_PATH);
          filenname.ReleaseBuffer();

          do work. You might want to check the return-code and GetLastErr() of GetModuleFileName.


          Who is 'General Failure'? And why is he reading my harddisk?!?

          M Offline
          M Offline
          Moonspellwizard
          wrote on last edited by
          #4

          Hello! Use _pgmptr or _wpgmptr Hope that helps :)

          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