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 3953626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:59:51+00:00 2026-05-20T01:59:51+00:00

I have a C program where I get function pointers dynamically by the function

  • 0

I have a C program where I get function pointers “dynamically” by the function name (ie. I pass the function name as a string and get a pointer to the function). I already do this in Linux using dlopen and dlsym and I suppose it will also work in any other Unix-like with dlfcn.

The problems began when I tried to port this program to Windows using MinGW. When I try to find the name using “GetProcAddress(handle, symbol_name), where “symbol_name” is the name of my callback function and “handle” is a handle to the current executable returned by “GetModuleHandle(NULL)”, I get nothing because the MinGW name mangling adds an “_” to my symbol name.

The obvious solution (prefix an “_” to the symbol I want) seems a bit ‘dangerous’ for portability (may the compiler add two underscores for some of them? I don’t know), so, I ask:

  • There is a better way to prevent the compiler from name-mangling my symbols? (or a subset of them, only the callbacks I need to find dynamically);

  • Or a way to make GetProcAddress find them even when mangled?

I also tried the option -fno-leading-underscore, but it removed the mangling of all the external symbols too, making the program impossible to link with the stdlib, etc. (also, the warnings on the documentation are a bit scary).

Also, please note that I’m using pure C — there is no C++ in any part of my code — and all my code lives in a single “.exe”.

TIA

  • 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-20T01:59:52+00:00Added an answer on May 20, 2026 at 1:59 am

    Not sure what your problem is, as I can’t reproduce it with the simplest DLL example I can think of:

    /* hello_dll.c */
    #include <stdio.h>
    
    __declspec(dllexport) void hello ( void )
    {
        puts ( "Hello, DLL!");
    }
    
    /* hello_exe.c */
    #include <windows.h>
    #include <stdio.h>  
    
    int main () {
        typedef void (*pfunc)(void);
    
        HANDLE hself;
    
        pfunc hello;
    
        hself = GetModuleHandle(NULL);
    
        hello = (pfunc)GetProcAddress(hdll, "hello");
    
        hello();
    
        return 0;
    }
    

    This is the command line using MinGW gcc with no special flags, and it all works:

    gcc src\hello_dll.c src\hello_exe.c -o bin\hello.exe
    $ bin\hello.exe
    Hello, DLL!
    $ gcc --version
    gcc (GCC) 4.5.0
    

    It doesn’t work without the __declspec(dllexport) if you are getting the function from yourself; when creating a DLL with gcc -shared it doesn’t appear to be necessary, but appears to be required if exporting a function from an exe.

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

Sidebar

Related Questions

I have written a program that uses qhttp to get a webpage. This works
I have a Java program which is using WMIC to get certain information about
I have the following code that calls the function uint32_pack. This program compiles with
I've written a simple string tokenizing program using pointers for a recent school project.
I have a program that makes use of the following method to get a
I have a small program that I'm trying to create to get ip addresses
I have a media program. i am adding CD,dvd,book info. I managed to get
I have to develop a program where I need to get the event from
How would I get the main program to recognize that I have an outside
I have been attempting to debug my program, but it always seems to get

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.