【发布时间】: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