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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:42:23+00:00 2026-05-18T07:42:23+00:00

I have a two-part program where the main core needs to have an adapter

  • 0

I have a two-part program where the main core needs to have an adapter registered and then call back into the register. The parts are in separate DLLs, and the core doesn’t know the adapter’s specifics (besides methods and parameters ahead of time). I’ve tried setting it up with the following code and recieve a segfault every time the core tries to call an adapter method:

Core.hpp/cpp (combined and simplified):

class Core
{
public:
    Core()
        : mAdapter(NULL)
    { }

    void DoStuff(int param)
    {
        if ( this->mAdapter )
        {
            this->mAdapter->Prepare(param);
        }
    }

    void Register(Adapter * adapter)
    {
        this->mAdapter = adapter;
    }

private:
    Adapter * mAdapter;
};

Adapter.hpp/cpp (in the core library):

class Adapter
{
public:
    Adapter(Core * core) { }

    virtual void Prepare(int param)
    {
        // For testing, this is defined here
        throw("Non-overridden adapter function called.");
    }
};

AdapterSpecific.hpp/cpp (second library):

class Adapter_Specific
    : Adapter
{
public:
    Adapter_Specific(Core * core)
    {
        core->Register(this);
    }

    void Prepare(int param) { ... }
};

All classes and methods are marked as DLL export while building the first module (core) and the core is marked as export, the adapter as import while building the adapter.

The code runs fine up until the point where Core::DoStuff is called. From walking through the assembly, it appears that it resolves the function from the vftable, but the address it ends up with is an 0x0013nnnn, and my modules are in the 0x0084nnnn and above range. Visual Studio’s source debugger and the intellisense shows the the entries in the vftable are the same and the appropriate one does go to a very low address (one also goes to 0xF-something, which seems equally odd).

Edit for clarity: Execution never re-enters the adapter_specific class or module. The supposed address for the call is invalid and execution gets lost there, resulting in the segfault. It’s not an issue with any code in the adapter class, which is why I left that out.

I’ve rebuilt both libraries more than once, in debug mode. This is pure C++, nothing fancy. I’m not sure why it won’t work, but I need to call back into the other class and would rather avoid using a struct of function ptrs.

Is there a way to use neat callbacks like this between modules or is it somehow impossible?

  • 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-18T07:42:24+00:00Added an answer on May 18, 2026 at 7:42 am

    The problem ended up being a stupid mistake on my part.

    In another function in the code, I was accidentally feeding a function a Core * instead of the Adapter * and didn’t catch it in my read-through. Somehow the compiler didn’t catch it either (it should have failed, but no implicit cast warning was given, possibly because it was a reference-counted point).

    That tried to turn the Core * into an Adapter and get the vftable from that mutant object, which failed miserably and resulted in a segfault. I fixed it to be the proper type and all works fine now.

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

Sidebar

Related Questions

I have a two part question Best-Practice I have an algorithm that performs some
So let's say I have two different functions. One is a part of the
Ok so part two of I have no will power experiment is: Summary Question
I have two threads, one needs to poll a bunch of separate static resources
I have a program that needs to repeatedly compute the approximate percentile (order statistic)
I have a WPF program built in C#, and part of it's function is
I have two applications written in Java that communicate with each other using XML
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two elements: <input a> <input b onclick=...> When b is clicked, I

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.