GetFileVersionInfoSize()导致无法加载Dll如果.Net未完全初始化 [英] GetFileVersionInfoSize() lead to failed to load a Dll If .Net isn't entirely initialized

查看:104
本文介绍了GetFileVersionInfoSize()导致无法加载Dll如果.Net未完全初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   ¥b $ b我有一个非常奇怪的问题导致无法加载静态Dll。

我会尝试解释它:



问题发生在我尝试注册的ActiveX的上下文中。此activeX / Dll具有多个依赖项。在这个依赖项的一个分支中,Dll在此Dll的DllMain()函数中调用函数GetFileVersionInfoSizeW()。在
调用此函数DllMain()之后,系统崩溃(regsvr32.exe中0x000007fef903aa5e的第一次机会异常)并且我没有任何callstack告诉我我在哪里。在放置一些断点后,似乎崩溃在内核Dll中,接近Dll加载的
结束。



第一个奇怪的是,如果我在我的Dll的DllMain()中删除了对GetFileVersionInfoSizeW()的调用,问题消失了。请注意,即使出现问题,函数GetFileVersionInfoSizeW()工作得很好,返回大小也很好,并且我没有使用此函数的
错误(在调用DllMain()之后出现错误)。

这里是DllMain()的代码:

    Hi,
I have a very strange problem that lead to failed to load a static Dll.
I will try to explain it:

The problem occur in the context of an ActiveX that I try to register. This activeX/Dll have multiple dependencies. In one branch of this dependencies, a Dll is calling the function GetFileVersionInfoSizeW() in its DllMain() function of this Dll. After the called of this function DllMain(), the system crash (First-chance exception at 0x000007fef903aa5e in regsvr32.exe) and I don't have any callstack that tell me where I am. After putting some breakpoint, it seems that the crash is in kernel Dll, near the end of the Dll loading.

The first strange thing is, if I removed the call to GetFileVersionInfoSizeW() in the DllMain() of my Dll, the problem disappear. Note that even when the problem occur, the function GetFileVersionInfoSizeW() work great, the return size is good, and I have no error with this function (the error appear after the call to DllMain()).
Here the code of DllMain():

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	{
		HINSTANCE InstanceRshDll1=::GetModuleHandleW(L"MyDllProblem.dll");
		if(InstanceRshDll1 == NULL)
		{
			throw int();
		}
		wchar_t ExeFileName[MAX_PATH];
		GetModuleFileNameW (InstanceRshDll1, ExeFileName, MAX_PATH);
		DWORD handle;
		DWORD dwSize  = ::GetFileVersionInfoSizeW(ExeFileName, &handle);
	}
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}




如果我将呼叫转移到"GetFileVersionInfoSizeW"在"DLL_THREAD_ATTACH"的情况下,问题也会消失。



当我更改Dll加载的顺序时,会出现这种奇怪的事情。如果是Microsoft dll"mscoreei.dll",在我的Dll调用GetFileVersionInfoSizeW()之前加载,问题就消失了!
$


所以我看看发生问题时加载的dll 当问题消失时似乎DLL"mscoree.dll"总是在我的dll之前加载,但是另一个DLL"mscoreei.dll"在
工作之前以及崩溃之后加载。

就像有些.Net初始化没有真正完成(如果"mscoreei.dll"尚未加载)这个行为在我的Dll中产生了崩溃...
$


这两个情况下加载的Dll列表:

当它崩溃时:
$


If I move the call to "GetFileVersionInfoSizeW" in the case "DLL_THREAD_ATTACH", the problem disappear too.

The very strange thing, appear when I change the order of the Dll loading. If the Microsoft dll "mscoreei.dll" is loaded before my Dll which make a call to GetFileVersionInfoSizeW(), the problem disappear !

So I have look to the dll which are loaded when the problem occurred and when the problem disappear. It seems that the DLL "mscoree.dll" is always loaded before my dll, but the other DLL "mscoreei.dll" is loaded before, when it works, and after when it's crash.
It's like some .Net initialization are not really finish (if "mscoreei.dll" isn't loaded yet) and this behavior generate a crash in my Dll...

Here the list of loaded Dll in the both case:
When it's crash:

'regsvr32.exe': Loaded 'C:\Windows\System32\regsvr32.exe', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk64.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_fa396087175ac9ac\comctl32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\apphelp.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\AppPatch\AppPatch64\AcGenral.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sspicli.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sfc.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sfc_os.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\userenv.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\profapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\mpr.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'ImageAtBase0x110000', Loading disabled by Include/Exclude setting.
'regsvr32.exe': Unloaded 'ImageAtBase0x110000'
'regsvr32.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\nvinitx.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\detoured.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\Nvd3d9wrapx.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\nvdxgiwrapx.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcr110.dll', Symbols loaded.
'regsvr32.exe': Loaded 'C:\Windows\System32\mfc110u.dll', Symbols loaded.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcp110.dll', Symbols loaded.
'regsvr32.exe': Loaded 'C:\Windows\System32\mscoree.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'E:\Sources\exe\Release_x64\MyDllProblem.dll', Symbols loaded.
'regsvr32.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file.
'regsvr32.exe': Unloaded 'C:\Windows\System32\msvcp110.dll'
First-chance exception at 0x000007fef903aa5e in regsvr32.exe: 0xC0000005: Access violation reading location 0x000007fee9a5aa56.
The program '[2392] regsvr32.exe: Native' has exited with code -1 (0xffffffff).




$
当它工作时:



When it works:

'regsvr32.exe': Loaded 'C:\Windows\System32\regsvr32.exe', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\AVAST Software\Avast\snxhk64.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_fa396087175ac9ac\comctl32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\apphelp.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\AppPatch\AppPatch64\AcGenral.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sspicli.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\shell32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sfc.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\sfc_os.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\userenv.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\profapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\mpr.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'ImageAtBase0x110000', Loading disabled by Include/Exclude setting.
'regsvr32.exe': Unloaded 'ImageAtBase0x110000'
'regsvr32.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\nvinitx.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\detoured.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\Nvd3d9wrapx.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\setupapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\cfgmgr32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\devobj.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Program Files\NVIDIA Corporation\coprocmanager\nvdxgiwrapx.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcr110.dll', Symbols loaded.
'regsvr32.exe': Loaded 'C:\Windows\System32\mfc110u.dll', Symbols loaded.
'regsvr32.exe': Loaded 'C:\Windows\System32\mscoree.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcp110.dll', Symbols loaded.
'regsvr32.exe': Loaded 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoreei.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\wininet.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-user32-l1-1-0.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-advapi32-l1-1-0.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-shlwapi-l1-1-0.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-version-l1-1-0.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\version.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\api-ms-win-downlevel-normaliz-l1-1-0.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\normaliz.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\iertutil.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\opengl32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\glu32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\ddraw.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\dciman32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\ws2_32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\nsi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\psapi.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcr100.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\msvcp100.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\comdlg32.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\winsxs\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17825_none_2b253c8271ec7765\GdiPlus.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'E:\Sources\exe\Release_x64\MyDllProblem.dll', Symbols loaded.
LoadLibrary succeeded'regsvr32.exe': Loaded 'C:\Windows\System32\duser.dll', Cannot find or open the PDB file.
LoadLibrary succeeded'regsvr32.exe': Loaded 'C:\Program Files\WIDCOMM\Bluetooth Software\BtMmHook.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\xmllite.dll', Cannot find or open the PDB file.
'regsvr32.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Cannot find or open the PDB file.




我试图制作一个可以重现问题的简单测试项目,但我没有做出可以在这里上传的例子。

我找到了一些解决方法来避免这个问题(改变Dll加载顺序,稍后调用函数'GetFileVersionInfoSizeW()',但我希望能理解我有这个问题,以避免将来出现一些新问题,并有一个真正的解决方案来解决这个问题。



问候,
$ b $bFrançois


I tried to make a simple test project that can reproduce the problem, but I failed to make a example that can be uploaded here.
I found some workaround to avoid this problem (change Dll loading order, call the function 'GetFileVersionInfoSizeW()' later), but I hope to understand with I have this problem to avoid some new problems in the future and have a real solution to this problem.

regards,
François

推荐答案

这就是它被告知的原因很多次,不要从DllMain调用任何可能导致递归加载器操作的东西。

This is exactly why it has been told many, many times not to call from DllMain anything that can cause recursive loader operations.

所以真正的解决方案是,从DllMain中删除所有可以删除的内容或者看起来很可疑。

So the real solution is, remove from DllMain everything that can be removed or just looks suspicious.

- pa


这篇关于GetFileVersionInfoSize()导致无法加载Dll如果.Net未完全初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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