在 Windows 7 上构建并在 Windows 2008 上运行:无法初始化应用程序 0xc0000005。在 C# 库上使用对包装器的引用

发布于 2024-11-04 05:13:41 字数 5534 浏览 0 评论 0原文

我正在 VS2010 和 Windows 7 (x86) 下构建 C++/MFC(我知道这是一项旧技术,但需要维护它)。在 Windows 2008 R2 (x64) 下运行应用程序很好,应用程序启动成功。
但是当我尝试在 Windows 2008 (x86) 或 Windows Server 2003 下运行该应用程序时,它失败,我在两个系统上都收到相同的错误:“应用程序失败正确初始化 (0xc0000005)。单击“确定”关闭应用程序”。

它对我来说看起来很奇怪,因为该应用程序是在 x86 系统下构建的,但仅在构建系统(win7 x86)和 x64 系统上运行!
其次,异常代码 0xc0000005 是什么意思?
有什么技巧可以找出 x86 系统中缺少哪些导致应用程序无法启动的内容吗?

这是来自 WinDbg 的日志:

Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: "C:\Documents and Settings\Administrator\Desktop\BINTest\C****.exe"
Symbol search path is: *** Invalid ***
****************************************************************************
* Symbol loading may be unreliable without a symbol search path.           *
* Use .symfix to have the debugger choose a symbol path.                   *
* After setting your symbol path, use .reload to refresh symbol locations. *
****************************************************************************
Executable search path is: 
ModLoad: 00400000 00581000   C*******.exe
ModLoad: 7c800000 7c8c2000   ntdll.dll
ModLoad: 77e40000 77f43000   C:\WINDOWS\system32\kernel32.dll
ModLoad: 77b90000 77b98000   C:\WINDOWS\system32\VERSION.dll
ModLoad: 77ba0000 77bfa000   C:\WINDOWS\system32\msvcrt.dll
ModLoad: 10000000 1001a000   C:\Documents and Settings\Administrator\Desktop\BINTest\S*****************.dll
ModLoad: 79000000 79046000   C:\WINDOWS\system32\mscoree.dll
ModLoad: 78aa0000 78b5d000   C:\Documents and Settings\Administrator\Desktop\BINTest\MSVCR100.dll
ModLoad: 78050000 780b9000   C:\Documents and Settings\Administrator\Desktop\BINTest\MSVCP100.dll
ModLoad: 003a0000 003c0000   C:\Documents and Settings\Administrator\Desktop\BINTest\R*********.dll
ModLoad: 003d0000 003d8000   C:\Documents and Settings\Administrator\Desktop\BINTest\Ch*****.dll
ModLoad: 78520000 785c3000   C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_D08D0375\MSVCR90.dll
ModLoad: 78b60000 78f8c000   C:\Documents and Settings\Administrator\Desktop\BINTest\mfc100.dll
ModLoad: 77380000 77412000   C:\WINDOWS\system32\USER32.dll
ModLoad: 77c00000 77c49000   C:\WINDOWS\system32\GDI32.dll
ModLoad: 77f50000 77fec000   C:\WINDOWS\system32\ADVAPI32.dll
ModLoad: 77c50000 77cef000   C:\WINDOWS\system32\RPCRT4.dll
ModLoad: 77da0000 77df2000   C:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 77530000 775c7000   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_5.82.3790.2778_x-ww_497C098C\COMCTL32.dll
ModLoad: 76280000 76285000   C:\WINDOWS\system32\MSIMG32.dll
ModLoad: 7c8d0000 7d0d4000   C:\WINDOWS\system32\SHELL32.dll
ModLoad: 77670000 777a4000   C:\WINDOWS\system32\ole32.dll
ModLoad: 77d00000 77d8c000   C:\WINDOWS\system32\OLEAUT32.dll
ModLoad: 71bb0000 71bb9000   C:\WINDOWS\system32\WSOCK32.dll
ModLoad: 71c00000 71c17000   C:\WINDOWS\system32\WS2_32.dll
ModLoad: 71bf0000 71bf8000   C:\WINDOWS\system32\WS2HELP.dll
ModLoad: 6d580000 6d628000   C:\WINDOWS\system32\dbghelp.dll
ModLoad: 76cf0000 76d0a000   C:\WINDOWS\system32\IPHLPAPI.DLL
ModLoad: 76b70000 76b7b000   C:\WINDOWS\system32\PSAPI.DLL
(87c.135c): Break instruction exception - code 80000003 (first chance)
eax=76c00000 ebx=7ffda000 ecx=00000003 edx=00000008 esi=7c88be14 edi=00151f38
eip=7c822577 esp=0012fb70 ebp=0012fcb4 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202
*** WARNING: symbols timestamp is wrong 0x49901641 0x45d70ad8 for ntdll.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll - 
ntdll!RtlMultiByteToUnicodeN+0x6002:
7c822577 cc              int     3
0:000> g
(87c.135c): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=77fc2324 ecx=fffffffc edx=00000000 esi=77fc2320 edi=00000004
eip=7c8396f0 esp=0012f030 ebp=0012f058 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010246
ntdll!strnicmp+0x22b:
7c8396f0 8b5014          mov     edx,dword ptr [eax+14h] ds:0023:00000014=????????
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\system32\ADVAPI32.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\system32\mscoree.dll - 



*下一步:删除项目中的依赖项。
我的项目依赖于另一个 C++ 项目 (R
**.dll),它是 C# 库的包装器。当删除此依赖项时,我的程序突然可以工作(至少它可以正常启动)。
如何链接此 DLL(包装器和 C#)?
与表现有关吗?
有什么想法吗?
这是应用程序的清单

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
<assemblyIdentity 
    version="1.0.0.0" 
    processorArchitecture="X86" 
    name="Microsoft.Windows.C****"
    type="win32" 
/> 
<description></description> 
<dependency> 
    <dependentAssembly> 
        <assemblyIdentity 
            type="win32" 
            name="Microsoft.Windows.Common-Controls" 
            version="6.0.0.0" 
            processorArchitecture="X86" 
            publicKeyToken="6595b64144ccf1df" 
            language="*" 
        /> 
    </dependentAssembly> 
</dependency> 
</assembly>

I am building a C++/MFC (I know it's an old technology, but need to maintain it) under VS2010 and Windows 7 (x86). Running the application under Windows 2008 R2 (x64) is fine, the application start with success.
But when I am trying to run the application under Windows 2008 (x86) or Windows Server 2003 it fails, I'm getting the same error on both systems : "The application failed to initialize properly (0xc0000005). Click Ok to close the Application".

It looks very stange to me since the app is built under a x86 system but runs only on built system (win7 x86) and on x64 system !
And secondly what does mean the exception code 0xc0000005?
Any tips find what is missing in the x86 systems that make the application unstartable?

here is the log from WinDbg:

Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: "C:\Documents and Settings\Administrator\Desktop\BINTest\C****.exe"
Symbol search path is: *** Invalid ***
****************************************************************************
* Symbol loading may be unreliable without a symbol search path.           *
* Use .symfix to have the debugger choose a symbol path.                   *
* After setting your symbol path, use .reload to refresh symbol locations. *
****************************************************************************
Executable search path is: 
ModLoad: 00400000 00581000   C*******.exe
ModLoad: 7c800000 7c8c2000   ntdll.dll
ModLoad: 77e40000 77f43000   C:\WINDOWS\system32\kernel32.dll
ModLoad: 77b90000 77b98000   C:\WINDOWS\system32\VERSION.dll
ModLoad: 77ba0000 77bfa000   C:\WINDOWS\system32\msvcrt.dll
ModLoad: 10000000 1001a000   C:\Documents and Settings\Administrator\Desktop\BINTest\S*****************.dll
ModLoad: 79000000 79046000   C:\WINDOWS\system32\mscoree.dll
ModLoad: 78aa0000 78b5d000   C:\Documents and Settings\Administrator\Desktop\BINTest\MSVCR100.dll
ModLoad: 78050000 780b9000   C:\Documents and Settings\Administrator\Desktop\BINTest\MSVCP100.dll
ModLoad: 003a0000 003c0000   C:\Documents and Settings\Administrator\Desktop\BINTest\R*********.dll
ModLoad: 003d0000 003d8000   C:\Documents and Settings\Administrator\Desktop\BINTest\Ch*****.dll
ModLoad: 78520000 785c3000   C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_D08D0375\MSVCR90.dll
ModLoad: 78b60000 78f8c000   C:\Documents and Settings\Administrator\Desktop\BINTest\mfc100.dll
ModLoad: 77380000 77412000   C:\WINDOWS\system32\USER32.dll
ModLoad: 77c00000 77c49000   C:\WINDOWS\system32\GDI32.dll
ModLoad: 77f50000 77fec000   C:\WINDOWS\system32\ADVAPI32.dll
ModLoad: 77c50000 77cef000   C:\WINDOWS\system32\RPCRT4.dll
ModLoad: 77da0000 77df2000   C:\WINDOWS\system32\SHLWAPI.dll
ModLoad: 77530000 775c7000   C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_5.82.3790.2778_x-ww_497C098C\COMCTL32.dll
ModLoad: 76280000 76285000   C:\WINDOWS\system32\MSIMG32.dll
ModLoad: 7c8d0000 7d0d4000   C:\WINDOWS\system32\SHELL32.dll
ModLoad: 77670000 777a4000   C:\WINDOWS\system32\ole32.dll
ModLoad: 77d00000 77d8c000   C:\WINDOWS\system32\OLEAUT32.dll
ModLoad: 71bb0000 71bb9000   C:\WINDOWS\system32\WSOCK32.dll
ModLoad: 71c00000 71c17000   C:\WINDOWS\system32\WS2_32.dll
ModLoad: 71bf0000 71bf8000   C:\WINDOWS\system32\WS2HELP.dll
ModLoad: 6d580000 6d628000   C:\WINDOWS\system32\dbghelp.dll
ModLoad: 76cf0000 76d0a000   C:\WINDOWS\system32\IPHLPAPI.DLL
ModLoad: 76b70000 76b7b000   C:\WINDOWS\system32\PSAPI.DLL
(87c.135c): Break instruction exception - code 80000003 (first chance)
eax=76c00000 ebx=7ffda000 ecx=00000003 edx=00000008 esi=7c88be14 edi=00151f38
eip=7c822577 esp=0012fb70 ebp=0012fcb4 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202
*** WARNING: symbols timestamp is wrong 0x49901641 0x45d70ad8 for ntdll.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll - 
ntdll!RtlMultiByteToUnicodeN+0x6002:
7c822577 cc              int     3
0:000> g
(87c.135c): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=77fc2324 ecx=fffffffc edx=00000000 esi=77fc2320 edi=00000004
eip=7c8396f0 esp=0012f030 ebp=0012f058 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010246
ntdll!strnicmp+0x22b:
7c8396f0 8b5014          mov     edx,dword ptr [eax+14h] ds:0023:00000014=????????
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\system32\ADVAPI32.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\system32\mscoree.dll - 

*Next step: Removing dependencies in my project.

My project has dependency on another c++ project (R**.dll) which is a wrapper to a C# library. When a remove this dependency my program suddenly works (at least it starts normally).
How can I link with this DLL's (wrapper and c#)?

Is it releated to manifest?

any idea?

here is the manifest of the app

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
<assemblyIdentity 
    version="1.0.0.0" 
    processorArchitecture="X86" 
    name="Microsoft.Windows.C****"
    type="win32" 
/> 
<description></description> 
<dependency> 
    <dependentAssembly> 
        <assemblyIdentity 
            type="win32" 
            name="Microsoft.Windows.Common-Controls" 
            version="6.0.0.0" 
            processorArchitecture="X86" 
            publicKeyToken="6595b64144ccf1df" 
            language="*" 
        /> 
    </dependentAssembly> 
</dependency> 
</assembly>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2024-11-11 05:13:41

您的问题的根本原因似乎是两个版本的 C++ 运行时库之间的冲突。

您的应用程序是使用 Visual Studio 2010 编译的,因此它需要版本 10 的 C++ 运行时,但它依赖于另一个加载 .NET CLR 版本 2 的 C++ 项目。该版本的 CLR 又需要版本 9 的 C++ 运行时。由于给定进程只能加载运行时的一个版本,因此会出现混乱。

简单的方法是使用 Visual Studio 2008 构建应用程序,或者修改相关项目,使其面向 .NET CLR 版本 4。这样,两个模块都会就要加载的 C++ 运行时版本达成一致。

困难的方法是将应用程序分成两个进程:一个加载依赖项目,另一个包含正确的应用程序,并使用某种形式的 IPC 在它们之间进行通信。这样,每个进程都能够加载自己版本的 C++ 运行时。

It seems that the root cause of your problem is a conflict between two versions of the C++ runtime libraries.

Your application is compiled with Visual Studio 2010, so it requires version 10 of the C++ runtime, but it depends on another C++ project that loads version 2 of the .NET CLR. That version of the CLR, in turn, requires version 9 of the C++ runtime. Since only one version of the runtime can be loaded by a given process, chaos ensues.

The easy way out is to either build your application with Visual Studio 2008, or modify the dependent project so it targets version 4 of the .NET CLR. That way, both modules will agree on the version of the C++ runtime to load.

The hard way is to split your application into two processes: one that loads the dependent project and one that contains the application proper, and use some form of IPC to communicate between them. That way, each process will be able to load its own version of the C++ runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文