加载库->免费图书馆->加载库 [英] Load Library -> Free Library -> Load Library

查看:68
本文介绍了加载库->免费图书馆->加载库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在项目中加载第3方DLL,所以我使用

HMODULE m_Instance;
...
m_Instance = LoadLibrary("ThirdParty.dll");



我的项目是主应用程序调用的另一个DLL.

应用程序有时会销毁我的DLL,然后重新创建它.

我的程序在死前调用FreeLibrary来卸载ThirdParty.dll.

该应用程序重新创建了我的DLL,因此在启动顺序中的某个位置,我再次调用LoadLibrary.

通话卡在了这里,不回话.

作为观察,我注意到一些可能与问题有关的东西:

加载ThirdParty.dll时,ThirdParty.dll会加载一大堆其他DLL.

卸载ThirdParty.dll时,如果正在调试,我可以在输出窗口中看到它正在卸载.但是,ThirdParty.dll似乎已加载的其余DLL并未列为正在卸载.

然后,在重新启动时(我的DLL已被释放并重新创建,但是主应用程序仍然存在),ThirdParty.dll被加载,并且卡住了.

我想知道在调用FreeLibrary时,是否无法正确释放ThirdParty.dll加载的DLL.

但是,这只是我的猜测,我希望情况并非如此,因为我无法解决ThirdParty.dll中的问题.

我可以做些什么来确保可以再次加载ThirdParty.dll?浮现在脑海:
看来ThirdParty.dll正在调皮,没有卸载其后代.因此,也许您可​​以在卸载后将其卸载.凌乱的X |或者,为什么要全部卸载呢? *如果*(如果很大),则您不依赖于重新加载时重新初始化ThirdParty.dll,可以在dll消失并返回时将其保留在那里吗?为此,ThirdParty.dll的初始加载将必须是有条件的-在其中执行GetProcAddress()或其他操作,以查看它是否已经存在.
我可能是在仰卧起坐,所以请随意射杀我!

祝你好运,
Peter


在我看来,如果您没有在您的入口点加载第3方库,则可能无法正确卸载第3方库图书馆对吗?

问候,

K,D


I have to load a 3rd party DLL in my project, so I use

HMODULE m_Instance;
...
m_Instance = LoadLibrary("ThirdParty.dll");



My project is yet another DLL that is called by the master application.

At some point the application destroys my DLL then recreates it.

In which time my program calls FreeLibrary to unload the ThirdParty.dll before dying.

The application recreates my DLL so somewhere in the start up sequence, I call LoadLibrary again.

The call gets stuck here and doesn''t return.

As an observation, here are some things I noticed that may have something to do with the problem:

When ThirdParty.dll is loaded, a whole bunch of other DLLs are loaded by ThirdParty.dll.

When ThirdParty.dll is unloaded, I can see it being unloaded in the output window if I''m debugging. However, the rest of the DLLs that ThirdParty.dll seemed to have loaded are not listed as being unloaded.

Then, on restart (my DLL has been released and recreated, but the main application has remained), ThirdParty.dll is loaded and that''s where it gets stuck.

I''m wondering if the DLLs loaded by ThirdParty.dll are not released appropriately when I call FreeLibrary.

However, that''s just my guess, and I rather hope that''s not the case because I can''t fix what'' in ThirdParty.dll.

Is there anything I can do to make sure I can load ThirdParty.dll a second time?

解决方案

I''m no expert in this area, but the following ideas come to mind:
It looks like ThirdParty.dll is being naughty and not unloading its descendants. So, maybe you could unload them after you unload it. Messy X| Alternatively, why unload it at all? *If* (a big if!) you don''t rely on ThirdParty.dll being reinitialised when you reload it, could you just leave it there while your dll goes away and returns? To do this, your initial load of ThirdParty.dll would need to be conditional - do a GetProcAddress() into it or something just to see if it''s already there.
I may be talking out of my situpon, so feel free to shoot me down!

Best of luck,
Peter


seems to me that the 3rd party library isn''t getting unloaded properly (i.e its messing up) by any chance your are not loading the 3rd party library in the entry point of your library right?

Regards,

K,D


这篇关于加载库->免费图书馆->加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆