简体   繁体   English

DLL 适用于 tlbimp,但不适用于 regsvr32.exe

[英]DLL Works with tlbimp, but not regsvr32.exe

I have a .dll that was made with MFC in a static library (C++).我在静态库 (C++) 中有一个用 MFC 制作的 .dll。 I am trying to use it in a Universal app(C#).我正在尝试在通用应用程序(C#)中使用它。 I was unable to reference the .dll in my universal app because I get the error: "Could not resolve COM Reference. The type library importer encountered an error during type verification."我无法在通用应用程序中引用 .dll,因为出现错误:“无法解析 COM 引用。类型库导入程序在类型验证期间遇到错误。”

I went to the solution here: The type library importer encountered an error during type verification And use tlbimp on my .dll.我转到这里的解决方案: 类型库导入程序在类型验证期间遇到错误并在我的 .dll 上使用 tlbimp。 It successfully pops out a new .dll, but gives a warning: "Importing a type library into a platform agnostic assembly. This can cause errors if the type library is not truly agnostic"它成功弹出一个新的 .dll,但给出警告:“将类型库导入平台不可知的程序集。如果类型库不是真正不可知的,这可能会导致错误”

NOTE: The original .dll is 3,000 kb and the tlbimp .dll is only 13 KB.注意:原始 .dll 为 3,000 kb,而 tlbimp .dll 只有 13 KB。 I suspect I am losing the MFC part and probably more.我怀疑我正在失去 MFC 部分,可能更多。

The new .dll is able to be referenced from my Universal App and I am able to use objects and functions from it.新的 .dll 可以从我的通用应用程序中引用,我可以使用它的对象和函数。 The program successfully compiles, but when I run the program, I get the runtime error: "Creating an instance of the COM component with CLSID using CoCreateInstanceFromApp failed due to the following error: 80040154 Class not registered" when I declare an object from the .dll.该程序成功编译,但是当我运行该程序时,当我从 . dll。

NOTE: The call is IHdevice device=new Hdevice();注意:调用是 IHdevice device=new Hdevice(); where IHdevice is an interface and Hdevice is the coclass其中 IHdevice 是一个接口,Hdevice 是 coclass

I suspected the tlb library was never registered, so I try to register with regsvr32, but when I do I get the error:我怀疑 tlb 库从未注册过,所以我尝试使用 regsvr32 注册,但是当我注册时出现错误:

"the module Lib.dll was loaded but the entry-point DllRegisterServer was not found" “模块 Lib.dll 已加载,但未找到入口点 DllRegisterServer”

I know for sure the original .dll has a DllRegisterServer function and is also defined in a .def file.我确信原始的 .dll 有一个 DllRegisterServer 函数并且也在 .def 文件中定义。 But I assume it is lost when I use tlbimp.但我认为当我使用 tlbimp 时它会丢失。 Is there a way to register and tlbimp at the same time?有没有办法同时注册和tlbimp? Is there any other suggestions you can offer?您还有什么其他建议可以提供吗?

Thanks in advance!提前致谢!

UPDATE: I have tried to use regsvr32 on the original .dll and it says "the module failed to load."更新:我尝试在原始 .dll 上使用 regsvr32,它说“模块加载失败”。 I have found http://csi-windows.com/blog/all/73-windows-64-bit/378-fixing-qregsvr32-the-module-failed-to-load-the-specified-module-could-not-be-foundq which seems like the same problem, but I have done everything in the solution.我发现http://csi-windows.com/blog/all/73-windows-64-bit/378-fixing-qregsvr32-the-module-failed-to-load-the-specified-module-could-not -be-foundq似乎是同样的问题,但我已经完成了解决方案中的所有事情。 I tried putting the dll in SysWOW64 and then trying.我尝试将 dll 放在 SysWOW64 中,然后尝试。 I tried putting the dll in System32 and then trying.我尝试将 dll 放在 System32 中,然后尝试。 I tried moving regsvr32 into the same directory and trying.我尝试将 regsvr32 移动到同一目录并尝试。 Everytime it cannot find the .dll.每次都找不到.dll。

I question: Does the .dll have to be COM visible for this to work.我的问题是: .dll 是否必须是 COM 可见的才能工作。 I don't believe anywhere I made the .dll COM visible, and I can't because I would need to have /clr which is incompatible with MFC static.我不相信我让 .dll COM 可见的任何地方,我不能,因为我需要 /clr 与 MFC 静态不兼容。

UPDATE2: I thought maybe the problem had to do with Universal Apps, so I made a console application, and made the same call. UPDATE2:我认为问题可能与通用应用程序有关,所以我制作了一个控制台应用程序,并进行了相同的调用。 This time the error is: "Retrieving the COM class factory for component with CLSID failed due to the following error: 8007007e The specified module could not be found."这次的错误是:“由于以下错误,检索具有 CLSID 的组件的 COM 类工厂失败:8007007e 找不到指定的模块。”

DONT DO THIS: HANS SAYS IT KILLS REGISTRATION!不要这样做:汉斯说这会影响注册! UPDATE3: I successfully used RegAsm on the tlbimp .dll (and it says "types registered successfully"). UPDATE3:我成功地在 tlbimp .dll 上使用了 RegAsm(它说“类型注册成功”)。 However, I still receive the same error at runtime: Creating an instance...failed due to..Class not registered.但是,我在运行时仍然收到相同的错误:Creating an instance...failed due to..Class notregistered。

.dll 依赖于其他 .dll,所以当它告诉我模块丢失时,这真的意味着丢失了一个不同的模块(我的 .dll 依赖的那个)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为64位操作系统包装32位dll以使用regsvr32.exe - wrap 32 bit dll for 64 bit operating system to work with regsvr32.exe 无法使用regsvr32注册我的DLL,但是通过IDE可以工作 - Unable to register my DLL using regsvr32, but via IDE works 如何使用 Regsvr32 注册 .NET COM DLL? - How do I register a .NET COM DLL with Regsvr32? Outlook赎回-在没有regsvr32 DLL的情况下使用RedemptionLoader - Outlook Redemption - using RedemptionLoader without regsvr32 the DLL .NET6:使用 regsvr32 注册 COM DLL 结果为 80040111 - .NET6: registering COM DLL with regsvr32 results in 80040111 RegAsm.exe和regsvr32有什么区别?如何使用regsvr32生成tlb文件? - What is difference between RegAsm.exe and regsvr32? How to generate a tlb file using regsvr32? 从类型库中使用tlbimp.exe重新生成interop.dll时,打开数组声明丢失 - Open array declaration lost when regenerating interop.dll with tlbimp.exe from type-lib TlbImp.exe无法注册lib文件:“。dll不是有效的类型库” - TlbImp.exe can't register lib file : “.dll is not a valid type library” Tlbimp无法生成Interop Dll - Tlbimp Failed Generating Interop Dll C#如何在没有注册的情况下使用遗留DLL(regsvr32) - How can C# use a legacy DLL simply without registration(regsvr32)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM