C#:DLL已注册,但COM错误80040154仍然出现 [英] C#: DLL is registered but COM error 80040154 still appear

查看:897
本文介绍了C#:DLL已注册,但COM错误80040154仍然出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调试我的 Windows窗体应用程序时,出现此错误:

When I debug my Windows Form Application I get this error:

使用CLSID检索组件的COM类工厂 {27526253-6119-4B38-A1F9-2DC877E72334}由于以下原因而失败 错误:80040154未注册类(HRESULT的异常: 0x80040154(REGDB_E_CLASSNOTREG))

Retrieving the COM class factory for component with CLSID {27526253-6119-4B38-A1F9-2DC877E72334} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

由于这个原因,我的 WFA 无法与计算机上安装的 Solidworks 软件交互; WFA 需要与 Solidworks 接口的唯一库是 SolidWorks.Interop.sldworks.dll(在 Solidworks 目录 C:\ Program Files \ SOLIDWORKS Corp 2017 \ SOLIDWORKS \ SolidWorks.Interop.sldworks.dll 中的本地位置).

and because of it, my WFA can't interface with the software Solidworks installed on my computer; the only library that WFA needs to interface with Solidworks is SolidWorks.Interop.sldworks.dll (native position in the Solidworks directory C:\Program Files\SOLIDWORKS Corp 2017\SOLIDWORKS\SolidWorks.Interop.sldworks.dll).

下面的其他信息.

  • 编译器: Microsoft Visual C#2010 Express
  • 操作系统: Microsoft Windows 7 64 bit(已更新)
  • 登录帐户:管理员
  • WFA的目标框架: Microsoft .NET Framework 4.0 Client 个人资料
  • WFA的体系结构:x86(32位)
  • 库的体系结构:x86(32位)
  • Compiler: Microsoft Visual C# 2010 Express
  • Operating system: Microsoft Windows 7 64 bit (updated)
  • Logged account: Administrator
  • Framework of destination of WFA: Microsoft .NET Framework 4.0 Client Profile
  • Architecture of WFA: x86 (32 bit)
  • Architecture of the library: x86 (32 bit)

当我通过 Visual Studio 将库SolidWorks.Interop.sldworks.dll添加到我的项目引用中时,没有CLSID

When I added the library SolidWorks.Interop.sldworks.dll into my project references, through Visual Studio, there wasn't the CLSID

{27526253-6119-4B38-A1F9-2DC877E72334}

{27526253-6119-4B38-A1F9-2DC877E72334}

进入 Windows注册表,因此我尝试通过以下方式注册该库:

into the Windows registry, so I tried to register that library in these ways:

    • SolidWorks.Interop.sldworks.dll粘贴到目录中 C:\ Windows \ SysWOW64
    • Administrator 身份运行命令提示符,而不是键入 C:\ Windows \ SysWOW64> regsvr32 C:\ Windows \ SysWOW64 \ SolidWorks.Interop.sldworks.dll
    • 按下 Enter
    • 阅读此消息:
    • Pasted SolidWorks.Interop.sldworks.dll into directory C:\Windows\SysWOW64
    • Ran Command Prompt as Administrator, than typed C:\Windows\SysWOW64>regsvr32 C:\Windows\SysWOW64\SolidWorks.Interop.sldworks.dll
    • Pressed Enter
    • Read this message:

模块 C:\ Windows \ SysWOW64 \ SolidWorks.Interop.sldworks.dll 是 加载但 呼叫DllRegisterServer失败...

The module C:\Windows\SysWOW64\SolidWorks.Interop.sldworks.dll was loaded but the call to DllRegisterServer failed...

因此,该库未注册.

    • SolidWorks.Interop.sldworks.dll粘贴到目录中 C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319
    • Administrator 身份运行命令提示符,而不是键入 C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319> regasm SolidWorks.Interop.sldworks.dll
    • 按下 Enter
    • 阅读此消息:
    • Pasted SolidWorks.Interop.sldworks.dll into the directory C:\Windows\Microsoft.NET\Framework\v4.0.30319
    • Ran Command Prompt as Administrator, than typed C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm SolidWorks.Interop.sldworks.dll
    • Pressed Enter
    • Read this message:

类型已注册.

The types were registered.

所以,我认为现在该库已注册,实际上我看到了CLSID

So, I think, now the library is registered, in fact I see the CLSID

{27526253-6119-4B38-A1F9-2DC877E72334}

{27526253-6119-4B38-A1F9-2DC877E72334}

进入 Windows注册表.

但是,问题仍然存在.

  1. 在我的C#代码中,我创建了new Guid;这是代码:

  1. In my C# code I created a new Guid; this is the code:

using System;
using System.Diagnostics;
using System.Windows.Forms;
using SolidWorks.Interop.sldworks;

namespace CreateModelSW
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    //Create interface
    SldWorks swApp;

    private void buttonCreateModel_Click(object sender, EventArgs e)
    {
        //Kill Solidworks processes
        Process[] processes = Process.GetProcessesByName("SLDWORKS");
        foreach (Process process in processes)
        {
            process.CloseMainWindow();
            process.Kill();
        }

        //Create new GUID
        Guid myGuid1 = new Guid("27526253-6119-4B38-A1F9-2DC877E72334");
        object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(myGuid1));

        //Create new SOLIDWORKS Part
        swApp = (SldWorks)processSW;
        swApp.Visible = true;
        swApp.NewPart();
    }
}
}

问题仍然存在.

你能帮我吗? 谢谢.

推荐答案

您应该使用与版本无关的progId,请尝试以下操作:

You should be using version agnostic progId, try this :

SldWorks swApp = (SldWorks)Activator.CreateInstance(System.Type.GetTypeFromProgID("SldWorks.Application"));

这篇关于C#:DLL已注册,但COM错误80040154仍然出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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