问题标签 [com-interop]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1881 浏览

c# - 将类型库导入为 C# 代码的工具

是否有将 COM 类型库导入/转换为 C# 代码而不是生成程序集的工具?TLBIMP 工具和 TypeLibaryConverter 类只生成程序集。

通过在生成的 Interop 程序集上运行 Reflector 并复制粘贴反汇编的源代码,我已经成功地翻录了 C#ComImport定义,但这通常需要在编译之前进行大量手动修补。

期望的目标是一个没有附属互操作 DLL 的单个 EXE,所以答案可能是使用 ILMerge 将互操作 DLL 有效地嵌入到 EXE 中。

我确信过去我会遇到这样的工具 - 但也许它梦想过它:-)

0 投票
2 回答
3285 浏览

c# - 将 C# 类库用作 COM+ 服务器应用程序

我在 C# 中创建了一个 .NET 类库并将其公开给 COM。它可以作为进程内 COM 服务器正常工作。但是,我想将它用作一个 out-proc COM 服务器,以便将它放在一个单独的进程中。

为此,我尝试创建一个 COM+ 应用程序。我创建了一个空的 COM+ 应用程序并将类库中实现的类添加到其中。当我调用 CoCreateInstance() 来实例化库中实现的类时,COM+ 代理进程遇到访问冲突并终止(崩溃转储如下)。

是否需要采取任何特殊步骤来创建可用作 COM+ 下的进程外 COM 服务器的类库?

COM+ 代理进程因以下故障转储而崩溃:

例外:C0000005
地址:0x000C1618

调用堆栈:
!+ 0xC1618
mscorwks!Ordinal79 + 0xE41C
mscorwks!Ordinal79 + 0xE4AD
mscorwks!CoInitializeEE + 0x563F
mscorwks!CoInitializeEE + 0x5672
mscorwks!CoInitializeEE + 0x57F1
mscorwks!CoInitializeCor + 0x210E
mscorwks!CoInitializeCor + 0x48D
mscorwks!Ordinal79 + 0x16D2
mscorwks!ReleaseFusionInterfaces + 0x20B28
COMSVCS! + 0xC29A2
COMSVCS!+ 0xC2BDA
COMSVCS!CoCreateStdTrustable + 0xCB10
ole32!CoMarshalInterface + 0x2642
ole32!CoInstall + 0x673
ole32!CoQueryAuthenticationServices + 0x1F44
ole32!CoQueryAuthenticationServices + 0x2862
ole32!CoWaitForMultipleHandles + 0xC267
ole32!CoQueryClientBlanket + 0x16CE
ole32!CoCreateObjectInContext + 0xC8E
ole32!CoInstall + 0x87A
ole32!CoWaitForMultipleHandles + 0x10479
ole32!CoMarshalInterface + 0x2808
ole32!CoGetTreatAsClass + 0xBE7
ole32!CoGetTreatAsClass + 0xB9E
ole32!CoMarshalInterface + 0x28F2
ole32!CoMarshalInterface + 0x2642
COMSVCS!CoCreateStdTrustable + 0x106A4
ole32!CoMarshalInterface + 0x2642
ole32!CoPopServiceDomain + 0x14FE
RPCRT4!CheckVerificationTrailer + 0x70
RPCRT4!NdrStubCall2 + 0x215
RPCRT4!CStdStubBuffer_Invoke + 0x82
ole32!StgGetIFillLockBytesOnFile + 0xFC92
ole32!StgFileCLock +
ole32!CoRevokeClassObject + 0xA3E
ole32!CoRevokeClassObject + 0x963
ole32!StgGetIFillLockBytesOnFile + 0xF872
ole32!WdtpInterfacePointer_UserMarshal + 0x80E
ole32!StgGetIFillLockBytesOnFile + 0xF792
RPCRT4!NdrGetTypeFlags + 0x1C9
RPCRT4!NdrGetTypeFlags + 0x12E
RPCRT4!NdrGetTypeFlags + 0x5A
RPCRT4!CreateStubFromTypeInfo + 0x2D7
RPCRT4!CreateStubFromTypeInfo + 0x318
RPCRT4!NdrConformantArrayFree + 0x2CB
RPCRT4!NdrConformantArrayFree + 0x20F
RPCRT4!I_RpcBCacheFree + 0x61C
RPCRT4!I_RpcBCacheFree + 0x43E
RPCRT4!I_RpcBCacheFree + 0x604
kernel32!GetModuleFileNameA + 0x1B4

0 投票
1 回答
687 浏览

excel - Excel 对 .NET DLL 的引用因新版本而中断

我有一个安装到 GAC 的 .NET DLL,因为它被多个应用程序使用。

其中之一是 Excel 工作簿,它使用 .NET 的 COM 互操作工具引用 DLL。COM tlb 文件安装到应用程序目录。

这一切都很好,除非安装了更新版本的 DLL。在某些 PC 上,工作簿中的 COM 引用中断(显示为“缺失”)。运行相关宏会使 Excel 崩溃。这可以通过取消勾选 VBA 编辑器中缺少的引用并重新添加对 DLL 的引用来解决,但我希望我的用户不必每次打开它时都这样做。

所有相关的对象和方法都具有不变的签名,并用不变的 GUID 进行装饰。

任何想法为什么参考中断?

编辑:在对注册表进行深入调查之后,看起来 COM 注册在安装时没有正确进行。但是,这并没有显示为安装失败。不过,仍然没有找到根本原因。

0 投票
2 回答
777 浏览

c++ - How to Manage COM Objects in .Net Web Application

A legacy c++ applications with sometimes notorious memory leak issues has to be called from a .Net server based windows application. .Net garbage collection times are not determinable and sometime the c++ object are destroyed or not destroyed "on time" producing unpredictable results and generally crashing the c# web app. What is the best way to push the c++ objects onto the garbage collection stack as frequently as possible, but not so often as to remove the .Net reference to the COM object. Keep in mind that the COM objects can spawn sub-objects so the .Net reference count of the COM objects can change with just a function call and not necessarily an instantiation.

As the memory leaks occur and the COM objects are not cleaned up, performance degrades until it is so slow that IIS trips on itself a few times and then crashes. Restarting IIS fixes the issue until the next time. Periodic restarts help, but a busy day can cause this during the business day.

I had to resolve this using .Net 1.1 a couple of years ago. Wondering if someone else had my solution or a better one. This is NOT ASP.NET. It is a .Net dll.

The final result was not completely satisfactory and the web server crashes every few months.

0 投票
1 回答
972 浏览

c# - 在 C# COM 对象上实现 IProvideClassInfo

我正在尝试IProvideClassInfo在 C# COM 对象上实现它,以便可以从 Windows 脚本主机 (WSH) 使用它的事件。我设法实现了接口并跟踪对我的GetClassInfo方法的调用。但是,连接事件失败并显示Cannot connect object.

有没有人设法做到这一点?

这是我的脚本代码(JScript):

0 投票
2 回答
1117 浏览

vb.net - dotNet 互操作用户控件的默认属性

我需要设置 VB6 应用程序使用的 dotNet 控件的默认属性。

DefualtProperty 属性不能解决问题。

我在这里读到手动将 DispId 设置为零应该可以解决问题。但如果我这样做:

Visual Basic 好心地通知我 DispId 零是为 DefaultProperty 保留的。是的。我知道。我要那个。但是怎么做?

编辑:

确实可以工作,因为该属性现在显示为 VB6 中的默认属性。但这不会解决我的问题,因为有些代码我无法更改,它会执行以下操作:

这篇 MSDN 文章有一些关于此的信息。

0 投票
2 回答
5196 浏览

.net - Excel 互操作: Range.FormatConditions.Add 抛出 MissingMethodException

我正在编写一个应用程序,它使用 Microsoft.Office.Interop.Excel 程序集从 Excel 电子表格导出/导入数据。一切都很好(除了基于 1 的索引和所有这些可选参数!),直到我尝试使用条件格式。当我调用 Range.FormatConditions.Add 时,我得到一个 MissingMethodException 告诉我不存在这样的方法。这在 Vista 和 XP 中都会发生。

以下是生成异常的代码示例:

0 投票
4 回答
3463 浏览

c# - 如何从 C# 方法返回 JavaScript“本机”数组?

我正在尝试使用以下方法从 JavaScript 调用 C# 方法ActiveXObject

最终,arr将包含一个SAFEARRAY对象,但不包含JScript数组。有没有办法从 C# 方法返回本机 JavaScript 对象?

0 投票
1 回答
260 浏览

c# - 如何从 ActiveXObject 访问 window.document 对象?

如何从 InternetExplorer 中的 ActiveXObject 访问 window.document 对象?我正在为我的 ActiveXObject 使用 C# 语言。

谢谢保罗。

0 投票
1 回答
247 浏览

delphi - 通过 Prism & Com Interop 公开功能

如何通过 COM Interop 公开一个用 Prism 编写的类?例如,给定以下接口:

在此示例中,假设 IFoo 通过 TLBIMP 导入并链接到项目。