problem with freeing memory in dll - Page 3
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 37 of 37

Thread: problem with freeing memory in dll

  1. #31
    Join Date
    Apr 1999
    Posts
    27,422

    Re: problem with freeing memory in dll

    Quote Originally Posted by rhboarder View Post
    one method that works is as zaccheus said using another external function in the dll to delete the object.
    I stated the same thing back in post #9, but for some reason, you just glossed over it.

    In general, the only memory allocation functions that work across compilers are the OS memory allocation functions. In Windows, you have GlobalAlloc(), HeapAlloc(), etc. These set of functions are guaranteed to be compatible across compilers, and even across different computer languages that have access to the Windows API functions.

    As far as Borland goes, I have a DLL written in Visual C++, and Borland compilers use it with no problems whatsoever. The DLL does as I stated -- it allocates and deallocates its own memory when it comes to "new" and "delete". In addition, any memory that the DLL wants to give to the app to handle for themselves, that memory is obtained using the OS functions, as mentioned previously.
    secondly, and this actually fixed my original
    problem with LoadLibrary/FreeLibrary. I was looking at the documentation for FreeLibrary and it says when it is called it will call DllMain. i didn't previously have that
    That shouldn't make any difference. If your DLL does not have a DllMain, then one is automatically added that does the default (return TRUE). So I don't know if you really fixed anything or your compiler is seriously broken in terms of producing valid DLL's.

    Regards,

    Paul McKenzie

  2. #32
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: problem with freeing memory in dll

    Quote Originally Posted by rhboarder View Post
    here's a link to a site i had found about exporting classes from a dll.
    http://www.codeproject.com/KB/cpp/ho...p_classes.aspx
    That's a great article!
    My hobby projects:
    www.rclsoftware.org.uk

  3. #33
    Join Date
    Nov 2009
    Location
    California
    Posts
    31

    Re: problem with freeing memory in dll

    sorry paul, i mustn't have seen that post. i thought the same thing that it shouldn't make a difference, so maybe it is my compiler.

  4. #34
    Join Date
    Apr 2004
    Posts
    2

    Re: problem with freeing memory in dll

    For your CreateObject to work correctly all class methods that you wish to use in the exe that are defined in the parent have to be virtual. This also includes the destructor. The reason for this is that the object returned via Createobject has a virtual function table which will give you access to the methods without a GetProcAddress

  5. #35
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: problem with freeing memory in dll

    A destructor only needs to be virtual if you want to call delete on a base class pointer.
    My hobby projects:
    www.rclsoftware.org.uk

  6. #36
    Join Date
    Apr 2004
    Posts
    2

    Re: problem with freeing memory in dll

    For the release to be implemented in the dll it would be doing a delete on the base class.

  7. #37
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: problem with freeing memory in dll

    Nope, release is always implemented in the most derived class.
    My hobby projects:
    www.rclsoftware.org.uk

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center