I have a C++ dll that is used by different UWP apps. Inside my dll I want to get the name of the running app. Standard winapi functions seem to not work, because they return exe names of some "wrappers" (e.g. ApplicationFrameHost.exe...).
Asked
Active
Viewed 505 times
-1
-
Probably related [How to get current AppInfo in UWP environment](https://stackoverflow.com/questions/44299452/how-to-get-current-appinfo-in-uwp-environment). – user7860670 Nov 13 '17 at 13:42
-
@VTT yeah, but I want to get the info from native code – DavitS Nov 13 '17 at 13:44
-
Those are UWP APIs that are available from native code. – user7860670 Nov 13 '17 at 13:45
1 Answers
0
As you can see [UWP]How to get running application name in UWP?, Azat Tazayan says you can like below to retrieve name
Package^ package = Package::Current;
PackageId^ packageId = package->Id;
String^ name= packageId->Name ;
But the above code is just return name of Package, if your exe file name is different with package name, above code is return incorrect name.
So you must use some code like below (based on How do I get the name of the current executable in C#?)
char filename[MAX_PATH];
DWORD size = GetModuleFileNameA(nullptr, filename, MAX_PATH);
std::reverse_iterator<char*> it = std::find_if(std::rbegin(filename), std::rend(filename), [](const char c) { return c == '\\'; });
const std::string exeName(it.base());

Dharman
- 30,962
- 25
- 85
- 135

sorosh_sabz
- 2,356
- 2
- 32
- 53