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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:18:10+00:00 2026-05-14T18:18:10+00:00

I have an unmanaged Win32 C++ application that uses multiple C++ DLLs. The DLLs

  • 0

I have an unmanaged Win32 C++ application that uses multiple C++ DLLs. The DLLs each need to use class Foo – definition and implementation.

Where do Foo.h and Foo.cpp live so that the DLLs link and don’t end up duplicating code in memory?

Is this a reasonable thing to do?

[Edit]
There is a lot of good info in all the answers and comments below – not just the one I’ve marked as the answer. Thanks for everyone’s input.

  • 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-14T18:18:11+00:00Added an answer on May 14, 2026 at 6:18 pm

    Providing functionality in the form of classes via a DLL is itself fine. You need to be careful that you seperate the interrface from the implementation, however. How careful depends on how your DLL will be used. For toy projects or utilities that remain internal, you may not need to even think about it. For DLLs that will be used by multiple clients under who-knows-which compiler, you need to be very careful.

    Consider:

    class MyGizmo
    {
    public:
      std::string get_name() const;
    private:
      std::string name_;
    };
    

    If MyGizmo is going to be used by 3rd parties, this class will cause you no end of headaches. Obviously, the private member variables are a problem, but the return type for get_name() is just as much of a problem. The reason is because std::string‘s implementation details are part of it’s definition. The Standard dictates a minimum functionality set for std::string, but compiler writers are free to implement that however they choose. One might have a function named realloc() to handle the internal reallocation, while another may have a function named buy_node() or something. Same is true with data members. One implementation may use 3 size_t‘s and a char*, while another might use std::vector. The point is your compiler might think std::string is n bytes and has such-and-so members, while another compiler (or even another patch level of the same compiler) might think it looks totally different.

    One solution to this is to use interfaces. In your DLL’s public header, you declare an abstract class representing the useful facilities your DLL provides, and a means to create the class, such as:

    DLL.H :

    class MyGizmo
    {
    public:
      static MyGizmo* Create();
      virtual void get_name(char* buffer_alloc_by_caller, size_t size_of_buffer) const = 0;
      virtual ~MyGizmo();
    private:
      MyGizmo();  // nobody can create this except myself
    
    };
    

    …and then in your DLL’s internals, you define a class that actually implements MyGizmo:

    mygizmo.cpp :

    class MyConcreteGizmo : public MyGizmo
    {
    public:
      void get_name(char* buf, size_t sz) const { /*...*/ }
      ~MyGizmo() { /*...*/ }
    private:
      std::string name_;
    };
    
    MyGizmo* MyGizmo::Create()
    {
      return new MyConcreteGizmo;
    }
    

    This might seem like a pain and, well, it is. If your DLL is going to be only used internally by only one compiler, there may be no reason to go to the trouble. But if your DLL is going to be used my multiple compilers internally, or by external clients, doing this saves major headaches down the road.

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

Sidebar

Related Questions

we have a C++ Win32 DLL that reads data from Excel. The application uses
I have a WPF click-once application that makes use of an unmanaged dll. When
I have an unmanaged assebmly (encryption functionality) that a VB.NET (2.0) installer class uses
The setup: I have a unmanaged/native Win32 application that I inject my code into.
I have a collection of unmanaged dlls with a C# wrapper around them that
OK, so I have a very large multi-threaded unmanaged c++ application (server) that runs
I have an unmanaged library which I want to use from a managed class.
I have a C++ unmanaged class NativeDog that needs to be used from C#,
We have a C++ unmanaged application that appears to cause a UAC prompt. It
I have an unmanaged struct I'd like to marshal to c sharp that looks

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.