-
November 16th, 2009, 05:58 AM
#31
Re: problem with freeing memory in dll
Originally Posted by rhboarder
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
-
November 16th, 2009, 09:46 AM
#32
Re: problem with freeing memory in dll
Originally Posted by rhboarder
That's a great article!
-
November 16th, 2009, 12:01 PM
#33
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.
-
November 18th, 2009, 04:49 PM
#34
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
-
November 18th, 2009, 06:56 PM
#35
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.
-
November 18th, 2009, 07:59 PM
#36
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.
-
November 19th, 2009, 09:25 AM
#37
Re: problem with freeing memory in dll
Nope, release is always implemented in the most derived class.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|