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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:30:16+00:00 2026-06-08T06:30:16+00:00

Given: Executable uses dll. They have different c/c++ runtime. Which restrictions do exist in

  • 0

Given: Executable uses dll. They have different c/c++ runtime. Which restrictions do exist in interface between them?
Besides they use the same compiler, the same Boost version (but different precompiled boost libs).

I understand that different runtime can have different heaps. So, delete must correspond to new from the same heap.

Most important that we cant pass via interface STL objects because when we build exe STL object are linked with one runtime
and when building dll the same object(if we pass it by reference or copy via interface) will be linked with another runtime.
And another runtime can have different implementation of that object.

Let’s consider cases:

  1. I think the following is safe. Dll exports function which has parameter: reference to exported user defined class that contains private STL class as member.
    Dll allocates memory for this object. Exe calls Release method of this object when want to delete it.

  2. I think the following is NOT safe. User defined class is instantiated in exe and passed via exe/dll interface.
    This class contains private STL class as member. exe and dll share headers/implementation files of this user class.
    When this class is built in separate projects different STL implementations will be used. For example different implementation
    of string::size() (from different runtimes) will be applied for the same object in memory.

  3. I think the following is safe. User defined class is instantiated in exe and passed via exe/dll interface.
    This class doesn’t depend on Standard library, it uses only primitive C++ types. exe and dll share headers/implementation files of this user class.
    Also we must control that new and delete correspond to the same heap. For example we can overload new / delete so them use ::GetProcessHeap.

  4. I think the following is NOT safe: passing boost objects via exe/dll interface because they can depend on Standard library classes. Also delete may not correspond to new’s heap.

  5. I think the following is NOT safe: even if we pass boost objects via exe/dll interface and they don’t depend on Standard library classes but not implemented as header only – than the object can be created with one boost lib (for one runtime)and used with another boost lib(for another runtime). Also delete may not correspond to new’s heap.

Also I want to use some flavor of smart pointer to pass reference to objects (mentioned in item 3) from exe to dll and from dll to exe.
I think this smart pointer should also overload new/delete to allocate reference counter from default process heap.
When it will try to delete pointed object it will call delete that overloaded by this object (as in item3)

For objects from item 1 I want to use custom smart pointer which will call release method of pointed object
(as boost::shared_ptr with custom release)

Which problems were not mentioned? Correct me please.

  • 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-06-08T06:30:19+00:00Added an answer on June 8, 2026 at 6:30 am

    The general answer to your question is: doing something to an object received from an EXE/DLL is safe if what is actually done does not depend on the runtime. E.g. vtable calls, function pointer calls, explicit function calls from DLL.

    Things that depend on the runtime (inline methods from header files, anything making any assumptions about STL object layout, etc.) are unsafe.

    Coming back to your examples:

    1. If you call the Release() method you should be careful and ensure that you’ll call the implementation of Release() from the DLL and not another implementation that was created by compiler making the EXE file. The easiest way to ensure it is to make Release() virtual so that the call is always a call using a method pointer from vtable (provided by DLL).

    2. Right, inline methods from STL like string::size() will cause problems here.

    3. Right. If new/delete are both overloaded to use GetProcessHeap(), the code will work.
    4. In general, right. In particular, see the implementation of the boost classes you need.
    5. If they don’t depend on STL and you’re sure that the memory footprint is the same for both compilers and you have provided custom new/delete(), it should not generally be a problem (see remarks below).

    Remarks:

    There are a few low-probability things that may cause problems not mentioned above:

    1. If you use different compilers, they might use different calling conventions by default (cdecl/stdcall).
    2. Default alignment options can also be different resulting in different memory layouts.
    3. If you throw exceptions from your DLL, the exe with a different runtime might not catch them, but crash instead.
    4. Marking the methods with DLL import/export attributes and ensuring that they are not inlined can be quite a hassle. Furthermore, if you are using different compilers, the C++ name mangling algorithm can be different.

    Having things summarized, it is recommended to look how things are implemented in Microsoft COM and design something similar. I.e. restrict the EXE/DLL interaction to:

    1. Interfaces. I.e. C++ classes with pure virtual methods only. Use virtual Release() to delete the objects.
    2. Simple clearly defined structures. Ensure that the alignment options for all compilers match. If you want to use non-trivial structures and you are using different compilers, better be paranoid and put checks like these:

      struct MyStruct
      {
          ...
      };
      C_ASSERT(sizeof(MyStruct) == ...);
      C_ASSERT(FIELD_OFFSET(MyStruct, MyMember) = ... );
      
    3. C-like functions passing and/or returning pointers to interfaces.

    4. Do not throw exceptions from the methods called by EXE
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a windows executable (.exe-file) which starts a given command.
We have a dot net 2.0 based C# product which uses Mysql as the
I have downloaded SSHCore source code which uses libssh2 library. That code build successfully,
I have been given a project where i need to write a program which
I have an application that uses a third party native C dll. Everything works
In my C# / .NET application I have to check if a given executable
Is it way to check whether given string represent executable in $PATH(%path%)? It have
I am writing an executable which uses dlopen() (LoadLibrary() on Windows) to dynamically load
so I have this project in java that uses a jni .dll i wrote
I am trying to find out if a given executable (or library) is compiled

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.