windows 0xc000007b 错误 - 但所有 DLL 都是 32 位

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8067299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:25:43  来源:igfitidea点击:

0xc000007b Error - but all DLLs are 32 bit

windowsvisual-studio-2008clr

提问by user375868

I am compiling my C++ code with /clr option using Visual Studio 2008 on Windows 7 32 bit OS targeting .NET Framework 3.5.

我正在使用 Visual Studio 2008 在面向 .NET Framework 3.5 的 Windows 7 32 位操作系统上使用 /clr 选项编译我的 C++ 代码。

All the DLLs are 32 bit (verified using Dependency Walker).

所有 DLL 都是 32 位的(使用 Dependency Walker 验证)。

As per my research this error comes up when 32 bit code calls 64 bit DLLs but this not the case here.

根据我的研究,当 32 位代码调用 64 位 DLL 时会出现此错误,但此处并非如此。

Are there any other root causes of error 0xc000007b?

错误 0xc000007b 是否还有其他根本原因?

采纳答案by user375868

Just happened to resolve this issue. It seems that this error is not onlycaused by mixing 64 bit libraries in 32 bit code but also when libraries are messed up - in my case I was using binary PCRE library.

刚好解决了这个问题。似乎这个错误不仅是由于在 32 位代码中混合了 64 位库引起的,而且是由于库混乱造成的——在我的情况下,我使用的是二进制 PCRE 库。

I built PCRE myself using MingW and now everything works fine.

我自己使用 MingW 构建了 PCRE,现在一切正常。

回答by Artur Mustafin

For use .NET FW 4.0, you should use legacy activation shim code to load .NET FW as COM component into your hosting app, like this:

要使用 .NET FW 4.0,您应该使用旧版激活填充代码将 .NET FW 作为 COM 组件加载到您的托管应用程序中,如下所示:

Use macro

使用宏

#define LEGACY_ACTIVATION_SHIM_ALLOW_LEGACY_API_FALLBACK

Sudoku.Runtime.h:

数独.Runtime.h:

#pragma once
// 
extern "C" int wWinMainCRTStartup();

Sudoku.Runtime.cpp:

数独.Runtime.cpp:

// Sudoku.Runtime.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

int _runtime()
{
    wWinMainCRTStartup();
    return 0;
}

int APIENTRY _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
    try
    {
        //CoInitializeEx(NULL, 0);              
        //CoUninitialize();
        HRESULT hr;     
        ICorRuntimeHost *pHost = NULL;
        hr = LegacyActivationShim::CorBindToRuntimeEx(NULL, NULL, STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, reinterpret_cast<LPVOID*>(&pHost));
        if (!FAILED(hr))
        {
            IUnknown *pAppDomainPunk = NULL;
            hr = pHost->CreateDomainEx(TEXT("_runtime"), NULL, NULL, &pAppDomainPunk);
            if (!FAILED(hr))
            {
                _::_AppDomain *pDefaultDomain = NULL;
                hr = pAppDomainPunk->QueryInterface(__uuidof(_::_AppDomain), reinterpret_cast<LPVOID*>(&pDefaultDomain));
                if (!FAILED(hr))
                {
                    _::_ObjectHandle *pObjHandle = NULL;
                    hr = pDefaultDomain->CreateInstance(_bstr_t("Sudoku"), _bstr_t("Sudoku.Runtime"), &pObjHandle); 
                    if (!FAILED(hr))
                    {
                        VARIANT v;
                        VariantInit(&v);
                        hr = pObjHandle->Unwrap(&v);
                        if (!FAILED(hr))
                        {
                            _::IRuntime *pRemotingHost = NULL;
                            hr = v.pdispVal->QueryInterface(__uuidof(_::IRuntime), (void**) &pRemotingHost);    
                            if (!FAILED(hr))
                            {
                                ::System::Reflection::Assembly^ ra = Assembly::GetExecutingAssembly();
                                array<::System::Byte>^ bytes = ra->GetName()->GetPublicKeyToken();
                                SAFEARRAY *psa = SafeArrayCreateVector(VT_UI1, 0, bytes->Length);
                                BYTE *pData;
                                hr = SafeArrayAccessData(psa, (void **)&pData);
                                if (!FAILED(hr))
                                {
                                    for(int i=0; i < bytes->Length; i++) pData[i] = bytes[i];
                                    hr = SafeArrayUnaccessData(psa);
                                    if (!FAILED(hr))
                                    {
                                        pRemotingHost->Run(psa);
                                    }
                                    pHost->UnloadDomain(pAppDomainPunk);
                                }
                            }
                            pObjHandle->Release();
                        }
                        pDefaultDomain->Release();
                    }
                    pAppDomainPunk->Release();
                }
                pHost->Release();
            }
            LegacyActivationShim::CorExitProcess(0);
        }
    }
    catch(...)
    {
    }
    return 0;
}

stdafx.h:

stdafx.h:

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"
// TODO: reference additional headers your program requires here

// Exclude rarely-used stuff from Windows headers
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN   

#import <mscorlib.tlb> auto_rename \
    rename("value", "___value") \
    rename("ReportEvent", "___ReportEvent") \
    rename_namespace("_") \
    raw_interfaces_only \
    high_property_prefixes("_get","_put","_putref")

#import "..\Public\Sudoku.tlb" auto_rename \
    rename_namespace("_") \
    raw_interfaces_only \
    high_property_prefixes("_get","_put","_putref")

// C RunTime Header Files
#include <tchar.h>

#include "cor.h"
#include "mscoree.h"
#include "strongname.h"

#include "Sudoku.Runtime.h"
#include "AssemblyInfo.h"
#include "Resource.h"


#define LEGACY_ACTIVATION_SHIM_ALLOW_LEGACY_API_FALLBACK

#include "LegacyActivationShimDelayLoad.h"

LegacyActivationShim.h:

LegacyActivationShim.h:

// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
//
// LegacyActivationShim.h
//
// This file allows simple migration from .NET Runtime v2 Host Activation APIs
// to the .NET Runtime v4 Host Activation APIs through simple shim functions.
// To use, just include this header file after the header file that declares the
// deprecated APIs you are using, and append the "LegacyActivationShim::" namespace
// in front of all deprecated API calls.
//
// For example,
//      #include "mscoree.h"
//      ...
//      CorBindToRuntimeEx(
//          NULL, NULL, 0, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&pRH));
// becomes
//      #include "mscoree.h"
//      #include "LegacyActivationShim.h"
//      ...
//      LegacyActivationShim::CorBindToRuntimeEx(
//          NULL, NULL, 0, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&pRH));
//
// To enable fallback to the legacy APIs when v4.0 is not installed on the machine,
// define LEGACY_ACTIVATION_SHIM_ALLOW_LEGACY_API_FALLBACK before including this
// header file.
//
// To use the legacy API fallback in a delay-loaded fashion, include LegacyActivationShimDelayLoad.h
// instead.
//

Sudoku.Runtime.cs:

数独.Runtime.cs:

[Serializable]
[ComVisible(true)]
[Obfuscation(Exclude = true)]
public class Runtime : IRuntime
{    
    public void Run(byte[] publikKeyToken)
    {
        Application.Run(publikKeyToken);
    }
}

[ComVisible(true)]
[Obfuscation(Exclude = true)]
public interface IRuntime
{
    void Run(byte[] publikKeyToken);
}