简体   繁体   中英

DLL Works with tlbimp, but not regsvr32.exe

I have a .dll that was made with MFC in a static library (C++). I am trying to use it in a Universal app(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."

I went to the solution here: The type library importer encountered an error during type verification And use tlbimp on my .dll. 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"

NOTE: The original .dll is 3,000 kb and the tlbimp .dll is only 13 KB. I suspect I am losing the MFC part and probably more.

The new .dll is able to be referenced from my Universal App and I am able to use objects and functions from it. 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.

NOTE: The call is IHdevice device=new Hdevice(); where IHdevice is an interface and Hdevice is the coclass

I suspected the tlb library was never registered, so I try to register with regsvr32, but when I do I get the error:

"the module Lib.dll was loaded but the entry-point DllRegisterServer was not found"

I know for sure the original .dll has a DllRegisterServer function and is also defined in a .def file. But I assume it is lost when I use tlbimp. Is there a way to register and tlbimp at the same time? 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." 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. I tried putting the dll in SysWOW64 and then trying. I tried putting the dll in System32 and then trying. I tried moving regsvr32 into the same directory and trying. Everytime it cannot find the .dll.

I question: Does the .dll have to be COM visible for this to work. 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.

UPDATE2: I thought maybe the problem had to do with Universal Apps, so I made a console application, and made the same call. 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."

DONT DO THIS: HANS SAYS IT KILLS REGISTRATION! UPDATE3: I successfully used RegAsm on the tlbimp .dll (and it says "types registered successfully"). However, I still receive the same error at runtime: Creating an instance...failed due to..Class not registered.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM