tags:

views:

50

answers:

2

Hello,

I have a program that is executed by another program. The program that is being executed needs files located at its own location [same folder]. If I call myfile.open("xpo.dll") I might get an error because I am not passing the [fullpath + name + extension]. The program that is being executed can vary paths depending on the installation path. Therefore, I was wondering if there is a way to get the application path [where the application is located] and set it so that when another program executes from another path everything might work properly...?

[Using C++ without .NET Framework]

Thanks.

+1  A: 

Use GetModuleFileName and pass NULL for hModule.

DWORD GetModuleFileName(
    HMODULE hModule,   // handle to module
    LPTSTR lpFilename, // path buffer
    DWORD nSize        // size of buffer
);
dmazzoni
A: 

First off, I run into this problem in other languages a lot, and find Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) very useful for finding out what folder it is currently trying to access.

There is no standard function for doing this.

  1. Just a thought, have you tried doing myfile.open "./xpo.dll"?

  2. If it's a console application, you can use the POSIX getcwd function: http://www.dreamincode.net/code/snippet77.htm

  3. If it's a Windows app and you can use the windows API, you can use GetModuleFileName... see the second reply to this question here: http://stackoverflow.com/questions/143174/c-c-how-to-obtain-the-full-path-of-current-directory

waitinforatrain