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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:43:32+00:00 2026-05-12T21:43:32+00:00

I am working with a legacy C library that can be extended by writing

  • 0

I am working with a legacy C library that can be extended by writing user defined function(s) and then recompiling the source. I want to avoid the compilation requirement, and instead extend it ONCE with a function (see pseudocode below):

This function will be implemented like this:

VARIANT_TYPE CallSharedLibFunction(const char* library_name, const char* funcname, const char *params, const char* return_type){
// parse arguments and get data types and count
// initiate variable of data type indicated by return_type, to hold returned variable

/* this is the part I need help with */
// lptr = LoadSharedLibrary(library_name);
// funcptr = GetFunctionAddress(lptr, funcname);

// call function and pass it arguments
retvalue = funcptr(param1, param2, param3);

// wrap up returned value in the VARIANT_TYPE
VARIANT_TYPE ret;
setVariantValue(ret, retvalue, return_type);

return ret;

}

Note: despite the “Windows sounding” names (VARIANT_TYPE, LoadSharedLibrary and GetFunctionAddress), I am developing on Linux (Ubuntu 9.10). Ideally, I would like the library loading implementation to be cross platform (since I am using ANSI C code). But if I have to choose one platform, it will have to be the Linux platform.

I would be very grateful if anyone could shed some light on how I can invoke functions in arbitrary shared libraries (ideally, in a cross platform way – failing that, on Linux), so that I can implement the above function.

  • 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-12T21:43:32+00:00Added an answer on May 12, 2026 at 9:43 pm

    You might want to have a look at the dlopen, dlsym and similar functions. These work on POSIX (linux, OSX, win32+cygwin etc…).

    With dlopen(), you can open a shared library. Your LoadSharedLibrary can be a wrapper around dlopen(). You GetFuncPtr() function can be a wrapper around dlsym(). What you can do is write code around the dl*() functions to make it robust – like do some error checking. You also might want to define an interface in the shared library, i.e. a struct that ‘exports’ supported functions. This way you can get a list of methods without the need to resorting to reading elf files.

    There is also a nice page about function pointers in C and C++.

    Here’s a quick example on the usage:

    void* LoadSharedLibrary(const char* name)
    {
       return dlopen(name, RTLD_LOCAL | RTLD_LAZY);
    }    
    
    void* GetFunctionAddress(void* h, const char* name)
    {
       return dlsym(h, name);
    }
    
    const char** GetFunctionList(void* h)
    {
       return (char**)dlsym(h, "ExportedFunctions");
    }
    
    // Declare a variable to hold the function pointer we are going to retrieve.
    // This function returns nothing (first void) and takes no parameters (second void).
    // The * means we want a pointer to a function.
    void (*doStuff)(void);
    
    // Here we retrieve the function pointer from the dl.
    doStuff = GetFunctionAddress(h, "doStuff");
    
    // And this how we call it. It is a convention to call function pointers like this.
    // But you can read it as 'take contents of the doStuff var and call that function'.
    (*doStuff)();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed a few times when working on legacy code, that you can
I'm working on a client/server library for a legacy RPC implementation and was running
I'm working on a legacy system that has uses stored procs, business objects and
I'm working on a legacy database table that has a phone no. field but
I'm working on legacy code that looks very similar to this: public class BaseParser
I am working on code (legacy code) which uses Apache Xerces-C library. I am
I'm working on legacy code that builds an index of popular terms in another
I'm working on upgrading a library that looks something like this (in coffeescript for
I'm working on a project that has a lot of legacy C code. We've
I'm working a legacy VC++6 app that is trying to add in unicode support,

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.