When I create a Rich Edit Control I load the DLL by calling
LoadLibrary("RichEd20.dll")
Do I have to call FreeLibrary() at some point? If so, when do I call it? Do I call it when the program ends? Thanks.
Printable View
When I create a Rich Edit Control I load the DLL by calling
LoadLibrary("RichEd20.dll")
Do I have to call FreeLibrary() at some point? If so, when do I call it? Do I call it when the program ends? Thanks.
You can put it after the message pump.
I think, I'm not 100% sure if thats the best place for it, but it should work.Code:// other WinMain code...
// Message pump
while(GetMessage(...))
{
TranslateMessage(...);
DispatchMessage(...);
// etc...
}
FreeLibrary(...);
// End of WinMain...
return static_cast<int>(msg.wParam);
Regards
-NotSoSuperHero.
call it in your CWinApp::ExitInstance() Function.Which is the right place to free the loaded libraryQuote:
Originally Posted by vironic
Thanx
humptydumpty
Is that for MFC? I'm using Win32 API.
Calling it in the end of program is fine.
Wasnt it like this that an NT system takes care of all open handles when a process exits ? If so, then there is no need to do a cleanup. I mean it can be a side effect of a system trying to reclaim "orphan" resources back, but in practice this gives programmer an ability to get away without cleanup, which takes time and program size. After all if a system has a map of all handles of a process, then theoretically a process dont have to cleanup..Quote:
Originally Posted by Krishnaa
I've heard this argument a couple of times. While this might work on Windows systems, it might not work on other systems (especially microcontrollers).Quote:
Originally Posted by Amn
Personally, I think this is a bad habit to get into.
My $0.02...
Viggy
Stylistically, I always try to add creation and cleanup code at the same time. The moment I add some creation code, I look for a complementary subtask/area where the cleanup fits in.
Programmatically, it is a good practise too. Say, the code that is now in the exe, is moved to another component , say DLL , and is invoked that way. In this case, since the cleanup code is there, the cleanup is not postponed to the end of the program, but to the unloading of the component.
In the OPs case, it might not matter since the process is exiting anyway. It is like a RegisterClass call. How many times have we seen a Win32 program calling RegisterClass but also calling UnregisterClass before exiting :) I haven't seen one so far :D
But , it is good practise to always cleanup at the right time. As MrViggy says, it is a bad habit to get into.
Well, i was not trying to advocate the approach really. I just wanted to point out the particular strategy in use by NT systems.Quote:
Originally Posted by MrViggy
I dont want to get off-topic to start another discussion here, but i think it is a fairly smart strategy where handles are owned and maintained by OS, so the program only needs to "borrow" them, and when a "process in memory" implies that when the process is unloaded all references to handles are taken care of - i.e. handles are returned to the system. my two cents :-)
I am in no way encouraging the practice, especially when going cross-platform for obvious reasons you stated.
I would like to question the need to LoadLibrary() for Rich Edit controls.Quote:
Originally Posted by vironic
How do you use this library?