【问题标题】:How to access COM objects from NodeJS如何从 NodeJS 访问 COM 对象
【发布时间】:2017-10-15 19:59:59
【问题描述】:

如何从 Node.js 访问 COM 对象。

我已经尝试过使用 Edge 的实现和使用 C# 的简单 DLL。当我调用调用函数时,DLL 中的一切都按预期工作,但 DLL 找不到指定的 COM 对象。然而,如果我在同一个 VS 解决方案中构建一个测试程序,然后从那里运行它,它就可以正常工作。

这是我的代码(这是我的代码中第一次实际使用 COM 对象,之前只是类型):

using QBXMLRP2Lib;
...
try { rp = new RequestProcessor2(); } catch (Exception e) { return e }

它返回这个错误:

{ Error: Retrieving the COM class factory for component with CLSID {45F5708E-3B43-4FA8-BE7E-A5F1849214CB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    at Error (native)
  ErrorCode: -2147221164,
  Message: 'Retrieving the COM class factory for component with CLSID {45F5708E-3B43-4FA8-BE7E-A5F1849214CB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).',
  Data: {},
  InnerException: null,
  TargetSite: {},
  StackTrace: 
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Startup.DoQBQuery(Object options) in c:\path\to\my\source\code\Startup.cs:line 35
  HelpLink: null,
  Source: 'mscorlib',
  HResult: -2147221164,
  message: 'Retrieving the COM class factory for component with CLSID {45F5708E-3B43-4FA8-BE7E-A5F1849214CB} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).',
  name: 'System.Runtime.InteropServices.COMException' }

【问题讨论】:

  • 这是一个注册问题。您是否使用 regasm/codebase 注册了 COM 对象?这也可能是由于 x86/x64 不匹配造成的。
  • 哈,这就是问题所在。我使用的是 64 位节点,而 QB XML 库是 32 位的。愿意把它放在答案中吗?

标签: c# node.js com quickbooks


【解决方案1】:

0x80040154 或 REGDB_E_CLASSNOTREG “类未注册”错误是一个非常常见的错误,表明存在 COM 对象注册问题。 COM 基本上告诉你它找不到你要找的对象。

在当今世界,大多数情况下,x86/x64 不匹配:客户端和服务器(当它是进程内 DLL 时)编译时的位数不同。

如果使用 .NET 作为 .DLL(进程内服务器),您还需要确保已使用 RegAsm /codebase 注册它,至少在开发/测试阶段是这样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 2010-12-12
    • 1970-01-01
    • 2011-02-03
    相关资源
    最近更新 更多