get current path

K

kk

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.
 
K

Keith Thompson

kk said:
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.

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).
 
T

TheMusikMan

kk said:
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.
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
 
J

jacob navia

kk said:
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.
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
 
K

Keith Thompson

jacob navia said:
You
#include <direct.h>

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.
 
T

TheMusikMan

direct.h: No such file or directory

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

What OS, etc are you running this on?

TheMusikMan
 
T

TheMusikMan

<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 GetCurrentDirectory function retrieves the current directory for the
current process.


DWORD GetCurrentDirectory(
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.
 
K

Keith Thompson

TheMusikMan said:
What OS, etc are you running this on?

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.)
 
K

Keith Thompson

TheMusikMan said:
<snip/>

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

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

Flash Gordon

TheMusikMan said:
<snip/>

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

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

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

goose

Flash Gordon wrote:

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

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

goose,
 
F

Flash Gordon

Flash Gordon wrote:



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

Damn. That's another job I can't apply for. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,835
Members
47,383
Latest member
EzraGiffor

Latest Threads

Top