Sign in to follow this  
aboeing

Win32 - C - Read Command Line Directory

Recommended Posts

Hi, I seem to be having trouble in reading the directory in which I execute a command. (Win32 program). Example: C:\something> myprogram myargument if I then print out the string returned by GetCommandLine, I get: myprogram myargument if I print out the string from GetCurrentDirectory I get: C:\install_location_of_myprogram How can I get the directory from which I ran my program? (ie: C:\something) ? (I have tried reading the environment variable CD but that didnt work either) Thanks!

Share this post


Link to post
Share on other sites
Not sure why your call to GetCommandLine is not returning the fully qualified path for you... it does this fine for me.

However, you can use GetModuleFileName which should do what you want...


GetModuleFileName(GetModuleHandle(NULL), filename_buffer, buffer_length);


Hope that helps!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this