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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:30:56+00:00 2026-05-11T02:30:56+00:00

Is there some way to make c++ dlls built with diffrent compilers compatible with

  • 0

Is there some way to make c++ dlls built with diffrent compilers compatible with each other? The classes can have factory methods for creation and destruction, so each compiler can use its own new/delete (since diffrent runtimes have there own heaps).

I tried the following code but it crashed on the first member method:

interface.h

#pragma once  class IRefCounted { public:     virtual ~IRefCounted(){}     virtual void AddRef()=0;     virtual void Release()=0; }; class IClass : public IRefCounted { public:     virtual ~IClass(){}     virtual void PrintSomething()=0; }; 

test.cpp compiled with VC9, test.exe

#include 'interface.h'  #include <iostream> #include <windows.h>  int main() {     HMODULE dll;     IClass* (*method)(void);     IClass *dllclass;      std::cout << 'Loading a.dll\n';     dll = LoadLibraryW(L'a.dll');     method = (IClass* (*)(void))GetProcAddress(dll, 'CreateClass');     dllclass = method();//works     dllclass->PrintSomething();//crash: Access violation writing location 0x00000004     dllclass->Release();     FreeLibrary(dll);      std::cout << 'Done, press enter to exit.' << std::endl;     std::cin.get();     return 0; } 

a.cpp compiled with g++ g++.exe -shared c.cpp -o c.dll

#include 'interface.h' #include <iostream>  class A : public IClass {     unsigned refCnt; public:     A():refCnt(1){}     virtual ~A()     {         if(refCnt)throw 'Object deleted while refCnt non-zero!';         std::cout << 'Bye from A.\n';     }     virtual void AddRef()     {         ++refCnt;     }     virtual void Release()     {         if(!--refCnt)             delete this;     }      virtual void PrintSomething()     {         std::cout << 'Hello World from A!' << std::endl;     } };  extern 'C' __declspec(dllexport) IClass* CreateClass() {     return new A(); } 

EDIT: I added the following line to the GCC CreateClass method, the text was correctly printed to the console, so its defenatly the function call thats killing it.

std::cout << 'C.DLL Create Class' << std::endl; 

I was wondering, how does COM manage to maintain binary compatibility even across languages, since its basicly all classes with inheritence (although only single) and therefore virtual functions. I’m not massivly bothered if I cant have overloaded operators/functions as long as I can maintain the basic OOP stuff (ie classes and single inheritence).

  • 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. 2026-05-11T02:30:57+00:00Added an answer on May 11, 2026 at 2:30 am

    You should be able to mix modules built with different compilers if you lower your expectations and stick to simple functions.

    The way classes and virtual functions behave is defined by the C++ standard, but the way that’s implemented is up to the compiler. In this case, I know that VC++ builds objects which have virtual functions with a ‘vtable’ pointer in the first 4 bytes of the object (I’m assuming 32-bit), and that points to a table of pointers to the method entry points.

    So the line: dllclass->PrintSomething(); is actually equivalent to something like:

    struct IClassVTable {     void (*pfIClassDTOR)           (Class IClass * this)      void (*pfIRefCountedAddRef)    (Class IRefCounted * this);     void (*pfIRefCountedRelease)   (Class IRefCounted * this);     void (*pfIClassPrintSomething) (Class IClass * this);     ... }; struct IClass {     IClassVTable * pVTab; }; (((struct IClass *) dllclass)->pVTab->pfIClassPrintSomething) (dllclass); 

    If the g++ compiler is implementing the virtual function tables in any way differently from MSFT VC++ — as it is free to do and still be conformant to the C++ standard — this will just crash as you’ve demonstrated. The VC++ code expects the function pointers to be in particular places in memory (relative to the object pointer).

    It gets more complicated by inheritance, and really, really, complicated with multiple inheritance and virtual inheritance.

    Microsoft has been very public about the way VC++ implements classes, so you can write code that depends on it. For example, a lot of COM object headers distributed by MSFT have both C and C++ bindings in the header. The C bindings expose their vtable structure like my code above does.

    On the other hand, GNU — IIRC — has left open the option of using different implementations in different releases, and just guaranteeing the programs built with it’s compiler (only!) will conform to the standard behaviour,

    The short answer is to stick to simple C-style functions, POD structures (Plain Old Data; i.e., no virtual functions), and pointers to opaque objects.

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

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From a purely linguistics point of view, the correct usage… May 11, 2026 at 5:52 pm
  • Editorial Team
    Editorial Team added an answer A few questions in there: In terms of disk I/O… May 11, 2026 at 5:52 pm
  • Editorial Team
    Editorial Team added an answer The compiler can change the execution order of statements when… May 11, 2026 at 5:52 pm

Related Questions

I want to use the new and delete operators for creating and destroying my
Several times in my career, I have worked in a software group that determined
We need to reliably get the Quick Launch folder for both All and Current
Here's the deal. Is there a way to have strings tokenized in a line

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.