I’m writing a short executable that will be run by both clicking on it and being called from another program (IDL). Is there a function that I can put in this executable that returns the path to itself? Since, “myprogram.exe” might be moved to a different location I don’t want to hard wire the path, but I want an outputted text file to end up in the same location as the executable. I’ve tried _fullpath, which returns the correct path if you double click on it, but returns the incorrect path if called from IDL.

Code:
sprintf(szBuffer,_fullpath( NULL, "myprogram.exe", _MAX_PATH ));
Double click on myprogram.exe -> C:\myprogram\ myprogram.exe

Call from IDL -> C:\Location_of_IDL_File\myprogram.exe

Any ideas, thanks,
Sulli_jj