Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
HMODULE hModule  = ::LoadLibrary("GameLogicWZQ.dll");
typedef GameObject* (*CreateObjProc)();
CreateObjProc pCreateProc = (CreateObjProc)::GetProcAddress(hModule,"CreateGameObject");
m_pGameObject = pCreateProc();
::FreeLibrary(hModule);


If the pCreateProc() function allocates a buffer size of 1024 (using new), then after calling ::FreeLibrary(hModule), will the buffer be free?
Posted
Updated 13-Jul-10 17:06pm
v2
Comments
Nish Nishant 13-Jul-10 23:07pm    
Reason for my vote of 5
Good question.

1 solution

No, it won't. A corresponding function should be exported from the DLL that frees that memory. And this function could be called (the same way the Create function is called).
 
Share this answer
 
Comments
henry3695 13-Jul-10 23:33pm    
If sad right
why after calling ::FreeLibrary(hModule);
I can't use the buffer?
Nish Nishant 13-Jul-10 23:47pm    
Actually you can. Have you tried doing that? If so, what did you observe?
henry3695 14-Jul-10 0:56am    
after ::FreeLibrary(hModule);
I can't use the buffer
I make srue it
Sauro Viti 14-Jul-10 2:45am    
It is possible that the DLL you are using keep trace of allocated memory and free it on its DllMain when it is called with DLL_PROCESS_DETACH reason. However the standard behaviour of DLL on Windows is the one that Nishant already said.
Jörgen Sigvardsson 16-Jul-10 16:42pm    
That would depend entirely on what C/C++-runtime is being used...?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900