• Advertisement
Sign in to follow this  

Win32 - C - Read Command Line Directory

This topic is 4207 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement