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

  • SEARCH
  • Home
  • 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 6214989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:58:27+00:00 2026-05-24T06:58:27+00:00

I want to get a dll’s directory (or file) path from within its code.

  • 0

I want to get a dll’s directory (or file) path from within its code. (not the program’s .exe file path)

I’ve tried a few methods I’ve found:
GetCurrentDir – gets the current directory path.
GetModuleFileName – gets the executable’s path.

So how can i find out in which dll the code is in ?
I’m looking for something similar to C#’s Assembly.GetExecutingAssembly

  • 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-05-24T06:58:29+00:00Added an answer on May 24, 2026 at 6:58 am

    You can use the GetModuleHandleEx function and get the handle to a static function in your DLL. You’ll find more information here.

    After that you can use GetModuleFileName to get the path from the handle you just obtained. More information on that call is here.

    A complete example:

    char path[MAX_PATH];
    HMODULE hm = NULL;
    
    if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 
            GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
            (LPCSTR) &functionInThisDll, &hm) == 0)
    {
        int ret = GetLastError();
        fprintf(stderr, "GetModuleHandle failed, error = %d\n", ret);
        // Return or however you want to handle an error.
    }
    if (GetModuleFileName(hm, path, sizeof(path)) == 0)
    {
        int ret = GetLastError();
        fprintf(stderr, "GetModuleFileName failed, error = %d\n", ret);
        // Return or however you want to handle an error.
    }
    
    // The path variable should now contain the full filepath for this DLL.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the icons of common file types in my dll. I
i want get the base address from one module, i was tried using GetModuleHandleEx
I want to get a (semi-colon separated) list of all .dll and .exe in
I want to get coverage of let's say CoverageTarget.dll. I have a test.dll to
I want to get this straight. I know what DLL's are. I have done
I want to set compilation debug=false to get release mode dll's compiled on the
I want to get the types and details in a plain Win32.dll just like
Which headers should I not use if I don't want my program to be
Possible Duplicate: How to programmatically get DLL dependencies On Windows, in a C++ program,
When I build my ASP.NET web application I get a .dll file with the

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.