0

Hi

I'm wondering if there is a simple win32 API to retrieve
the current module filename (xxxx.exe)

I know about GetModuleFilename which gets the full path.
And I have read that argv[0] holds the exe name, but that also give me the full path.

What I'm after is an API to give me just the name, with or without an extension.

Any simple solutions?

2
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by Suzie999
1

Simply strip away the path from the names you get from GetModuleFilename or args[0]. As in:

#include <iostream>
#include <string>
#include <algorithm>

int main(int argc, char** argv) {

  std::string full_name = argv[0];

  std::cout << "Full name: " << full_name << std::endl;

  std::string exec_name(std::find(full_name.rbegin(),
                                  full_name.rend(),
                                  '\\').base(), 
                        full_name.end());

  std::cout << "Exec name: " << exec_name << std::endl;

  return 0;
};
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.