My application implements a plugin architecture of sorts, using LoadLibrary
, GetProcAddress
and FreeLibrary
. Since all my dlls are in the same directory as the executable, when I look for a dll, I get the executable's directory and search there, using this function:
string FileSystem::GetPathToProgramDirectory(){
char progname[MAX_PATH];
GetModuleFileNameA( NULL, progname, MAX_PATH );
PathRemoveFileSpecA( progname );
return string( progname );
}
This works on production, but when I try to run this under an integration test using NUnit, the executable directory ends up being NUnit's, and so loading fails.
Bear in mind, this is unmanaged C++; in managed C++ I solved this using Path::GetDirectoryName(Assembly::GetExecutingAssembly()->Location)
, which works in both cases, but the unmanaged case got me stumped. Is there an unmanaged Winapi equivalent for that?