Reputation: 2074
I have a C++/CLI dll and I'd like to know what the preferred alternative to the Win32 API function GetModuleFilename
would be. I've found Assembly::GetExecutingAssembly()->ManifestModule->FullyQualifiedName
(MSDN). This seems to be working, but I'd like to know if there's a different or "better" way. Of course, I know that technically nothing prohibits me from using GetModuleFilename
directly, but I hate mixing different APIs and this would also require to create a string buffer which I'd then have to convert back into a System::String
. I know it's only two more lines of code but still ... ;-)
Upvotes: 1
Views: 1149
Reputation: 941635
Don't use GetModuleFileName()
, the .NET 4.0 CLR has dropped some appcompat code that makes a loaded assembly resemble a regular DLL. Besides, the HMODULE is trouble, you cannot use the VirtualQuery trick to convert a code address to a HMODULE.
Assembly::GetExecutingAssembly()->Location
gives you the full path to the assembly from which the IL for the current method was loaded.
Upvotes: 5