Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:15:56+00:00 2026-06-04T21:15:56+00:00

Possible Duplicate: Extracting the current executable name I created a program that reads configuration

  • 0

Possible Duplicate:
Extracting the current executable name

I created a program that reads configuration from ini file, the name of that file should be identical to name of executable but of course with its extension. So If I name it myprogram.exe the config should be myprogram.ini, and if I change name of the exe after compilation it should look accorting to its new name.

I know that it is possible to get program name from argv[0] but this works only if it starts from command line, when it is clicked in explorer this array is empty.

As I read through the answers here I think it has to do something with this function: https://stackoverflow.com/a/10572632/393087 – But I can’t find any good example of usage of that function, I’m very beginner to c++ and general function definitions (like that presented on microsoft pages) are too hard for me to understand, but when I get a working example it is a snap for me to comprehend.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:15:57+00:00Added an answer on June 4, 2026 at 9:15 pm
    #include <windows.h>
    #include <Shlwapi.h>
    // remember to link against shlwapi.lib
    // in VC++ this can be done with
    #pragma comment(lib, "Shlwapi.lib")
    
    // ...
    
    TCHAR buffer[MAX_PATH]={0};
    TCHAR * out;
    DWORD bufSize=sizeof(buffer)/sizeof(*buffer);
    // Get the fully-qualified path of the executable
    if(GetModuleFileName(NULL, buffer, bufSize)==bufSize)
    {
        // the buffer is too small, handle the error somehow
    }
    // now buffer = "c:\whatever\yourexecutable.exe"
    
    // Go to the beginning of the file name
    out = PathFindFileName(buffer);
    // now out = "yourexecutable.exe"
    
    // Set the dot before the extension to 0 (terminate the string there)
    *(PathFindExtension(out)) = 0;
    // now out = "yourexecutable"
    

    Now in out you have a pointer to the “base name” of your executable; keep in mind that it points inside buffer, so when buffer goes out of scope out is not valid anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Extracting text from HTML file using Python What is the best way
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: how to delete a file? My application first reads the fields in
Possible Duplicate: Extracting indices for data frame rows that have MAX value for named
Possible Duplicate: Recommended way to initialize srand? I am extracting frames from AVI. I
Possible Duplicate: Extracting the content of an element from an external page Is there
Possible Duplicate: How do I pass parameters to the File::Find subroutine that processes each
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Reading a .doc (MSWord) file in ObjectiveC? I am writing a printing
Possible Duplicate: What are the stages of compilation of a C++ program? I find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.