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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:48:50+00:00 2026-05-22T21:48:50+00:00

I am trying to make a DLL file compatible with different compiler configurations (Debug,

  • 0

I am trying to make a DLL file compatible with different compiler configurations (Debug, Release,..). In order to make sure that an object is removed the right way I managed to write a pointer wrapper class that uses a compiled delete operator whenever I take an object of the DLL and run out of scope.

I am perfectly fine with this but my program crashes when I try to delete memory that I allocated in the very same method/program.

Here is some sample code compiled in a standard Release mode:

header

template <typename T>
class API mwCompatibleObject
{
public:

    //! Constructor
    mwCompatibleObject();

    //! Destructor
    virtual ~mwCompatibleObject();
};

source code

template < typename T >
mwCompatibleObject< T >::mwCompatibleObject() {}

template <typename T>
mwCompatibleObject<T>::~mwCompatibleObject() {}

Note: API is defined as export/import.

Now I use this very class in a Debug mode application where I create an instance and delete it right away.

mwCompatibleObject<double> * obj = new mwCompatibleObject<double>();
delete obj;

Executing the delete operator gives an access violation at mlock.c line 376.

Here is a copy of the callstack:

ntdll.dll!7721e3be()    
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
msvcr80d.dll!_unlock(int locknum=4)  Line 376   C
msvcr80d.dll!_heap_alloc_dbg(unsigned int nSize=0, int nBlockUse=2968120, const char * szFileName=0x2e2ed26c, int nLine=1638180)  Line 477 + 0x7 bytes  C++
msvcr80d.dll!_heap_alloc_dbg(unsigned int nSize=0, int nBlockUse=2968120, const char * szFileName=0x2e2ed26c, int nLine=1638180)  Line 474 + 0xc bytes  C++
00300000()  
msvcr80d.dll!malloc(unsigned int nSize=2968120)  Line 154 + 0x15 bytes  C++
5axutil.dll!100b5d09()  
Integrator3.exe!main()  Line 54 + 0x34 bytes    C++

I can’t jump into that line or anything but I managed to get a look at the Assembler code which proves my observation that it has to do with the destructor.

Is there a general problem with virtual functions/destructors when trying to make a DLL compatible?

  • 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-22T21:48:51+00:00Added an answer on May 22, 2026 at 9:48 pm

    You can’t export a template definition as the compiler generates the types based on usage of the template. You simply inline them in the header file or you can do something like this but that requires declaring your template instantiation upfront.

    Also note in C++ prefer new and delete over malloc and free functions from C especially if you actually want constructors and destructors to be called.

    Edit:

    I would seriously consider inlining of the template preferable to any attempt to export. Also I failed to note originally that virtual destructors are only needed if your class will be a base class or contain virtual methods. Why have a vtable with nothing in it?

    template <typename T>
    class mwCompatibleObject // no need for export if inlined in header
    {
    public:
        //! Constructor
        mwCompatibleObject() {}
        //! Destructor (don't need virtual unless it's a base class or has virtual methods)
        ~mwCompatibleObject() {}
    
        //! Some public method
        void DoSomething(const T& withSomething)
        {
            // ... yata yata
        }
    private:
        T m_member;
    };
    

    Further Edit:

    I just found out that exporting template support will be completely removed (not deprecated, removed) from the new C++ standard when it is finalized. Inline templates in header files will be the only solution that compilers will implement and allow in the very near future, so get used to writing them this way now. See Herb Sutter’s Questions & Answers about C++0x

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

Sidebar

Related Questions

I'm currently trying to build a C++ library (DLL file) that interfaces with a
I'm trying to make a method of compressing file using Ionic.Zip.dll of DotNetZip. Code
Trying to make a make generic select control that I can dynamically add elements
Trying to make a custom :confirm message for a rails form that returns data
Im trying to make a function that will return an element of type point:
I'm trying to make a macro in VBA for Delmia. That macro need to
Im trying to make a small app in c++ that saves midifiles with this
I'm trying to debug a 32 bit process dump from a process that ran
I'm trying to make a small game that supports Python scripting. I've no problems
I am trying to make a wrapper for a native c++ .dll using P/Invoke.

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.