Click to See Complete Forum and Search --> : Application's directory


Andrew Truckle
April 6th, 1999, 05:48 AM
I've used the following to get my dialogs application directory:

CString gPath;

GetModuleFileName(NULL, gPath.GetBuffer(_MAX_PATH), _MAX_PATH);
gPath.ReleaseBuffer();

gPath = gPath.Left(gPath.ReverseFind('\\') + 1);


Is this the best way?

Walter I An
April 6th, 1999, 07:32 AM
Hi! Andrew. It's me again.
I am not sure what exact U want to do.
But if ur want to find the directory
of ur app. How about GetCurrentDrectory()?

Good luck with your Work! :)

Walter

Walter I An
April 6th, 1999, 07:36 AM
Sorry for misspelling!

It's GetCurrentDirectory()!!!

:)
Walter

Andrew Truckle
April 6th, 1999, 07:40 AM
Yes, but surely, isn't it possible that a user may adjust the "start up directory" of their short-cut which would change the current directory from that of where the program actually resides?

Andrew Truckle
April 6th, 1999, 08:36 AM
Hi Walter

I tried GetCurrentDirectory()

It returned c:\video instead of c:\video\debug which is where the exe is.

Walter I An
April 6th, 1999, 10:24 AM
Did you run your App from VC IDE or
your App?

As I try if U ran ur App in VC IDE,
it chopps \debug. But if run from ur
App, I believe it will show full path.

Try again if U didn't.

:)

Walter

Andrew Truckle
April 8th, 1999, 01:59 AM
Hi Walter

I think you are right.

I've ended up not using this code anyway since I've added the AVI file as a resource.

But atleast I know the principle of how to get the directory. But, suppose someone modifies the properties of a short-cut to the program where they change the "startup directory", will it still return the programs location?

Regards

Martin Speiser
April 8th, 1999, 03:42 AM
Hi Andrew,

GetCurrentDirectory will always return the current directory, as the name says. This means, if someone sets the working directory to another dir, it will return this. Or if you use the common file dialog, it will change the current directory by default.

Your first attempt with GetModuleFileName was correct.


Martin