装载程序锁(regsvr32 R6033错误)与托管C ++ DLL [英] Loader lock (regsvr32 R6033 error) with managed C++ dll

查看:286
本文介绍了装载程序锁(regsvr32 R6033错误)与托管C ++ DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++ dll它实现几个COM接口,我试图迁移到托管C ++。我设置/ clr编译器标志,并将运行时库属性从/ MT更改为/ MD,以避免这两个标志之间的冲突,但这是我所有的更改。当在构建过程中尝试注册dll时,我得到以下错误:

I have a C++ dll which implements several COM interfaces, that I'm trying to migrate to managed C++. I set the /clr compiler flag and changed the Runtime Library property from /MT to /MD to avoid the conflict between these two flags, but that's all I've changed. When it attempts to register the dll during the build process, I get the following error:

R6033 - 在本机代码初始化期间尝试使用MSIL代码
这表示您的应用程序中有一个错误。这很可能是从本机构造函数或从DllMain调用MSIL编译(/ clr)函数的结果。

R6033 - Attempt to use MSIL code from this assembly during native code initialization This indicates a bug in your application. It is most likely the result of calling an MSIL-compiled (/clr) function from a native constructor or from DllMain.

无法弄清楚 - 我没有添加任何托管代码的单个调用。这是整个DllMain过程的主体:

I read about Loader Lock and can't figure it out - I have not added a single call to any managed code. Here's the entire body of the DllMain procedure:

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    lpReserved;
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        _Module.Init(ObjectMap, hInstance, &MYGUID);
        DisableThreadLibraryCalls(hInstance);
    }
    else if (dwReason == DLL_PROCESS_DETACH)
        _Module.Term();
    return TRUE;    // ok
}


推荐答案

这是Visual Studio的向导的作用,下面是如何使用托管代码而不是整个项目的文件。我已测试:

This is what the Visual Studio "Wizard" does, here is how I've tested:


  • 创建Visual C ++ ATL项目

  • 添加了ATL简单对象,以便具有COM接口(Project-> Add Class)

  • 添加了CLR组件类。向导提示您正在将一个CLR组件添加到本机项目中,您的项目将转换为具有Common Language Runtime支持。

  • 检查项目设置 - >无公共语言运行时支持

  • 检查clrcomponennt.cpp设置 - >公共语言运行库支持(/ clr)

  • 在OleView - > COM界面中打开了dll

  • 在Red Gate的.NET Reflector - > clrcomponent中打开了dll

  • Create a Visual C++ ATL Project
  • Added a ATL Simple Object, in order to have a COM interface (Project->Add Class)
  • Added a CLR Component Class. The Wizard prompted me with "You are adding a CLR component to a native project. Your project will be converted to have Common Language Runtime support."
  • Compile project, compiles fine and registers fine.
  • Checked the project settings -> "No Common Language Runtime support"
  • Checked the clrcomponennt.cpp settings -> "Common Language Runtime Support (/clr)"
  • Opened the dll in OleView -> COM interface was present
  • Opened the dll in Red Gate's .NET Reflector -> clrcomponent was present

这篇关于装载程序锁(regsvr32 R6033错误)与托管C ++ DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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