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

The Archive Base Latest Questions

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

For my current project I want to be able to load some classes from

  • 0

For my current project I want to be able to load some classes from a dll (which is not always the same, and may not even exist when my app is compiled). There may also be several alternative dll’s for a given class (eg an implementation for Direct3D9 and one for OpenGL), but only one of the dlls will be loaded/used at any one time.

I have a set of base classes that define the interface plus some basic methods/members (ie the ones for refrence counting) of the classes I want to load, which the dll projects then derive from when creating there classes.

//in namespace base class Sprite : public RefCounted//void AddRef(), void Release() and unsigned refCnt { public:     virtual base::Texture *GetTexture()=0;     virtual unsigned GetWidth()=0;     virtual unsigned GetHeight()=0;     virtual float GetCentreX()=0;     virtual float GetCentreY()=0;     virtual void SetCentre(float x, float y)=0;      virtual void Draw(float x, float y)=0;     virtual void Draw(float x, float y, float angle)=0;     virtual void Draw(float x, float y, float scaleX, flota scaleY)=0;     virtual void Draw(float x, float y, float scaleX, flota scaleY, float angle)=0; }; 

The thing is I’m not sure how to do it all so that the executable and other dlls can load and use these classes since ive only ever used dlls where there was only one dll and I could have the Visual Studio linker sort it all out using the .lib file I get when compileing dll’s.

I dont mind using factory methods for instancing the classes, many of them do already by design (Ie a sprite class is created by the main Graphics class, eg Graphics->CreateSpriteFromTexture(base::Texture*)

EDIT: When I needed to write some c++ dlls for use in python I used a library called pyCxx. The resulting dll basicly only exported one method, which created an instance of the ‘Module’ class, which could then contain factory methods to create other classes etc.

The resulting dll could be imported in python just with ‘import [dllname]’.

//dll compiled as cpputill.pyd extern 'C' void initcpputill()//only exported method {     static CppUtill* cpputill = new CppUtill; }  class CppUtill : public Py::ExtensionModule<CppUtill> { public:     CppUtill()     : Py::ExtensionModule<CppUtill>('cpputill')     {         ExampleClass::init_type();          add_varargs_method('ExampleClass',&CppUtill::ExampleClassFactory, 'ExampleClass(), create instance of ExampleClass');         add_varargs_method('HelloWorld',  &CppUtill::HelloWorld,  'HelloWorld(), print Hello World to console');          initialize('C Plus Plus module');     } ... class ExampleClass ...     static void init_type()     {         behaviors().name('ExampleClass');         behaviors().doc ('example class');         behaviors().supportGetattr();         add_varargs_method('Random', &ExampleClass::Random, 'Random(), get float in range 0<=x<1');     } 

How exactly does that work, and could I use it in a purely c++ enviroment to solve my problem here?

  • 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:28:29+00:00Added an answer on May 11, 2026 at 2:28 am

    Easiest way to do this, IMHO, is to have a simple C function that returns a pointer to an interface described elsewhere. Then your app, can call all of the functions of that interface, without actually knowing what class it is using.

    Edit: Here’s a simple example.

    In your main app code, you create a header for the interface:

    class IModule { public:     virtual ~IModule(); // <= important!     virtual void doStuff() = 0; }; 

    Main app is coded to use the interface above, without any details on the actual implementation of the interface.

    class ActualModule: public IModule { /* implementation */ }; 

    Now, the modules – the DLL’s have the actual implementations of that interface, and those classes don’t even have to be exported – __declspec (dllexport) isn’t needed. The only requirement for the modules is to export a single function, that would create and return an implementation of the interface:

    __declspec (dllexport) IModule* CreateModule() {     // call the constructor of the actual implementation     IModule * module = new ActualModule();     // return the created function     return module; } 

    note: error checking left out – you’d usually want to check, if new returned the correct pointer and you should protect yourself from the exceptions that might be thrown in the constructor of the ActualModule class.

    Then, in your main app, all you need is to simply load the module (LoadLibrary function) and find the function CreateModule (GetProcAddr function). Then, you use the class through the interface.

    Edit 2: your RefCount (base class of the interface), can be implemented in (and exported from) the main app. Then all your module would need to link to the lib file of the main app (yes! EXE files can have LIB files just like DLL files!) And that should be enough.

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

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • 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
  • added an answer Thanks for comments and sorry for my mistake, I found… May 11, 2026 at 3:54 pm
  • added an answer listConnections on the .target attr the cleanup in mel: string… May 11, 2026 at 3:54 pm
  • added an answer This works for me: int DoDOS(string parms) { Process p=new… May 11, 2026 at 3:53 pm

Related Questions

I've been looking for a webserver for my project but I haven't been able
I wanted to emulate a popular flash game, Chrontron, in C++ and needed some
I'm building a heavily CRUD based ASP.NET website and I've got to the phase
I cannot figure out how to enable per-session instances for my WCF service while

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.