CuriousGeorge
CuriousGeorge

Reputation: 7410

When do C++ DLLs get freed in C#?

I have a C++ DLL that is loaded into a C# Windows Forms app. I am trying to create an opengl context with the dll, and preserve it for use in the managed app while the dll is unloaded/reloaded. I am using LoadLibrary and FreeLibrary to load the DLL.

Is this possible? If the C++ DLL loads the opengl DLL, will the opengl dll be unloaded if I call FreeLibrary on the DLL that loaded it? And is it safe to store the unmanaged objects that were created by the c++ DLL in managed code and reuse them with the new instance of that DLL?

Upvotes: 0

Views: 311

Answers (1)

Simple Fellow
Simple Fellow

Reputation: 4622

If the OpenGL dl was also loaded with the Load Library call then unloading the DLL will not affect it unless you specifically unload it. If it was loaded automatically by the system then it will be unloaded when you unload the C++ dll. You can use the OpenGL context as long as the OpenGl is not unloaded and the window handle which was used in the creation of OpenGL context remains valid.

But I wonder why don't you call the OpenGL dll directly from your application ?

Upvotes: 2

Related Questions