get current path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kk

    get current path

    Can any function tell the compiled program executing path? after using the
    program to open a file from MFC dialog box, the path changes. thks in
    advance.


  • Keith Thompson

    #2
    Re: get current path

    "kk" <kk-leung@cuhk.edu. hk> writes:[color=blue]
    > Can any function tell the compiled program executing path? after using the
    > program to open a file from MFC dialog box, the path changes. thks in
    > advance.[/color]

    We don't know. Your question doesn't seem to be about the C
    programming language, so we can't answer it here. Try a newsgroup
    where they talk about MFC (whatever that is).

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.

    Comment

    • TheMusikMan

      #3
      Re: get current path

      kk wrote:[color=blue]
      > Can any function tell the compiled program executing path? after using the
      > program to open a file from MFC dialog box, the path changes. thks in
      > advance.
      >
      >[/color]
      I have only dealt with the situation once and didn't find a solution to
      grab the execution path "as the execution path". I did however, find a
      way to grab the current path (though the call slips my mind right now
      and it was done in Linux, not Windows), but you can grab the execution
      path first thing, then let your program do whatever it needs to do, Msft
      Foundation Classes not-with-standing.

      TheMusikMan

      Comment

      • jacob navia

        #4
        Re: get current path

        kk wrote:
        [color=blue]
        > Can any function tell the compiled program executing path? after using the
        > program to open a file from MFC dialog box, the path changes. thks in
        > advance.
        >
        >[/color]
        You
        #include <direct.h>

        ....
        _getcwd(int buflen, char *pathbuffer);

        This will put the current path into pathbuffer up to buflen chars.

        Then there is
        _chdir(char *path);

        that will set the current path to the given one.

        One way to avoid changing the path is to get the path before
        calling the file open dialog, then setting the path to the saved
        one after the dialog exists.

        But a more simpler way is to tell the program not to change the
        path. The file open dialog has a flag to avoid changing the path
        Look in the SDK documentation.

        jacob

        Comment

        • Keith Thompson

          #5
          Re: get current path

          jacob navia <jacob@jacob.re mcomp.fr> writes:[color=blue]
          > kk wrote:[color=green]
          >> Can any function tell the compiled program executing path? after using the
          >> program to open a file from MFC dialog box, the path changes. thks in
          >> advance.
          >>[/color]
          > You
          > #include <direct.h>[/color]

          I get:

          direct.h: No such file or directory

          There is no <direct.h> header in standard C. This is why we have
          system-specific newsgroups.

          --
          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
          We must do something. This is something. Therefore, we must do this.

          Comment

          • TheMusikMan

            #6
            Re: get current path

            Keith Thompson wrote:[color=blue]
            > jacob navia <jacob@jacob.re mcomp.fr> writes:
            >[color=green]
            >>kk wrote:
            >>[color=darkred]
            >>>Can any function tell the compiled program executing path?[/color][/color][/color]

            <snip>
            [color=blue]
            >
            > direct.h: No such file or directory
            >
            > There is no <direct.h> header in standard C. This is why we have
            > system-specific newsgroups.
            >[/color]

            What OS, etc are you running this on?

            TheMusikMan

            Comment

            • TheMusikMan

              #7
              Re: get current path

              Keith Thompson wrote:
              [color=blue]
              > jacob navia <jacob@jacob.re mcomp.fr> writes:
              >[color=green]
              >>kk wrote:
              >>[color=darkred]
              >>>Can any function tell the compiled program executing path?[/color][/color][/color]

              <snip/>

              If you are running basically anything Windows, then the Windows API call
              for current directory (according to Msft VS.NET) is as follows:

              The GetCurrentDirec tory function retrieves the current directory for the
              current process.


              DWORD GetCurrentDirec tory(
              DWORD nBufferLength,
              LPTSTR lpBuffer
              );

              Parameters
              nBufferLength
              [in] Length of the buffer for the current directory string, in TCHARs.
              The buffer length must include room for a terminating null character.
              lpBuffer
              [out] Pointer to the buffer that receives the current directory string.
              This null-terminated string specifies the absolute path to the current
              directory.
              Return Values
              If the function succeeds, the return value specifies the number of
              characters written to the buffer, not including the terminating null
              character.

              If the function fails, the return value is zero. To get extended error
              information, call GetLastError.

              If the buffer pointed to by lpBuffer is not large enough, the return
              value specifies the required size of the buffer, in characters,
              including the null- terminating character.

              <snipped remarks/>

              Requirements
              Client: Included in Windows XP, Windows 2000 Professional, Windows NT
              Workstation, Windows Me, Windows 98, and Windows 95.
              Server: Included in Windows Server 2003, Windows 2000 Server, and
              Windows NT Server.
              Unicode: Implemented as Unicode and ANSI versions. Note that Unicode
              support on Windows Me/98/95 requires Microsoft Layer for Unicode.
              Header: Declared in Winbase.h; include Windows.h.
              Library: Use Kernel32.lib.

              Comment

              • Keith Thompson

                #8
                Re: get current path

                TheMusikMan <musikman79@acc ess-4-free.com> writes:[color=blue]
                > Keith Thompson wrote:[color=green]
                >> jacob navia <jacob@jacob.re mcomp.fr> writes:
                >>[color=darkred]
                >>>kk wrote:
                >>>
                >>>> Can any function tell the compiled program executing path?[/color][/color]
                >
                > <snip>
                >[color=green]
                >> direct.h: No such file or directory
                >> There is no <direct.h> header in standard C. This is why we have
                >> system-specific newsgroups.[/color]
                >
                > What OS, etc are you running this on?[/color]

                It really doesn't matter. The point, as I said, is that the is no
                <direct.h> header in standard C. If there's one on your system,
                that's fine, but you need to be aware that it's system-specific, and
                that comp.lang.c isn't the place to discuss it.

                (But since you ask, I get the same result on Cygwin under Windows XP,
                on Solaris, and on Linux.)

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                We must do something. This is something. Therefore, we must do this.

                Comment

                • Keith Thompson

                  #9
                  Re: get current path

                  TheMusikMan <musikman79@acc ess-4-free.com> writes:[color=blue]
                  > Keith Thompson wrote:[color=green]
                  >> jacob navia <jacob@jacob.re mcomp.fr> writes:
                  >>[color=darkred]
                  >>>kk wrote:
                  >>>
                  >>>> Can any function tell the compiled program executing path?[/color][/color]
                  >
                  > <snip/>
                  >
                  > If you are running basically anything Windows, then the Windows API
                  > call for current directory (according to Msft VS.NET) is as follows:[/color]
                  [snip]

                  Then the place to discuss it is comp.os.ms-windows.program mer.win32.
                  It's off-topic here.

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                  We must do something. This is something. Therefore, we must do this.

                  Comment

                  • Flash Gordon

                    #10
                    Re: get current path

                    On Fri, 15 Oct 2004 06:21:34 GMT
                    Keith Thompson <kst-u@mib.org> wrote:
                    [color=blue]
                    > TheMusikMan <musikman79@acc ess-4-free.com> writes:[color=green]
                    > > Keith Thompson wrote:[color=darkred]
                    > >> jacob navia <jacob@jacob.re mcomp.fr> writes:
                    > >>
                    > >>>kk wrote:
                    > >>>
                    > >>>> Can any function tell the compiled program executing path?[/color]
                    > >
                    > > <snip/>
                    > >
                    > > If you are running basically anything Windows, then the Windows API
                    > > call for current directory (according to Msft VS.NET) is as follows:[/color]
                    > [snip]
                    >
                    > Then the place to discuss it is comp.os.ms-windows.program mer.win32.
                    > It's off-topic here.[/color]

                    <OT>
                    It is also technically incorrect since Win3.1 is also Windows as is
                    WinCE etc. Of course, no one here knows that ;-)
                    </OT>
                    --
                    Flash Gordon
                    Sometimes I think shooting would be far too good for some people.
                    Although my email address says spam, it is real and I read it.

                    Comment

                    • goose

                      #11
                      Re: get current path

                      Flash Gordon wrote:

                      <snipped>
                      [color=blue]
                      > <OT>
                      > It is also technically incorrect since Win3.1 is also Windows as is
                      > WinCE etc. Of course, no one here knows that ;-)
                      > </OT>[/color]

                      and if they did know OT information, chances are that they'd
                      fake ignorance well enough to mark MCSE papers ;-)

                      goose,

                      Comment

                      • Flash Gordon

                        #12
                        Re: get current path

                        On Fri, 15 Oct 2004 23:35:53 -0700
                        goose <ruse@webmail.c o.za> wrote:
                        [color=blue]
                        > Flash Gordon wrote:
                        >
                        > <snipped>
                        >[color=green]
                        > > <OT>
                        > > It is also technically incorrect since Win3.1 is also Windows as is
                        > > WinCE etc. Of course, no one here knows that ;-)
                        > > </OT>[/color]
                        >
                        > and if they did know OT information, chances are that they'd
                        > fake ignorance well enough to mark MCSE papers ;-)[/color]

                        Damn. That's another job I can't apply for. :-)
                        --
                        Flash Gordon
                        Sometimes I think shooting would be far too good for some people.
                        Although my email address says spam, it is real and I read it.

                        Comment

                        Working...