com-interop

Pass a buffer of chars from .NET to COM and get it back updated

怎甘沉沦 提交于 2019-12-22 09:39:40
问题 I have the following COM method to be called from C#, which returns a string in the provided buffer pchText (which is not necessarily zero terminated) and the number of characters copied in pcch : HRESULT Next([in, out] long* pcch, [out, size_is(*pcch)] OLECHAR* pchText); How do I define the C# signature for interop? So far, I tried this: void Next(ref int pcch, [MarshalAs(UnmanagedType.LPWStr, SizeParamIndex = 0)] System.Text.StringBuilder pchText); It appears to work, but I am not sure if

How to properly clean up interop objects in C#

元气小坏坏 提交于 2019-12-22 06:24:59
问题 This is a follow on question to How to properly clean up excel interop objects in c#. The gyst is that using a chaining calls together (eg. ExcelObject.Foo.Bar() ) within the Excel namespace prevents garbage collection for COM objects. Instead, one should explicitly create a reference to each COM object used, and explicitly release them using Marhsal.ReleaseComObject(). Is the behaviour of not releasing COM objects after a chained call specific to Excel COM objects only? Is it overkill to

How to properly clean up interop objects in C#

淺唱寂寞╮ 提交于 2019-12-22 06:24:39
问题 This is a follow on question to How to properly clean up excel interop objects in c#. The gyst is that using a chaining calls together (eg. ExcelObject.Foo.Bar() ) within the Excel namespace prevents garbage collection for COM objects. Instead, one should explicitly create a reference to each COM object used, and explicitly release them using Marhsal.ReleaseComObject(). Is the behaviour of not releasing COM objects after a chained call specific to Excel COM objects only? Is it overkill to

Visual Studio 2010: Embed Interop Types

时光毁灭记忆、已成空白 提交于 2019-12-22 03:50:11
问题 I found some information about this on Scott Hanselmans Blog Does anybody exactly know what this mean? Is this only for the Office Primary Interop Assemblies, or can I also use this to Embed my Redemption library or other COM libraries? 回答1: The process described in Scott Hanselman's blog is called Type Equivalence , a rather nebulous term for the CLR 4.0's support for COM interop type assemblies. Although I haven't had a chance to look at it, there is a video here at Channel 9 that discusses

C# How do you get an instance of a COM interface

人盡茶涼 提交于 2019-12-21 21:54:33
问题 I've been doing quite a bit of googling trying to find the standard way to get an instance of a COM interface. Microsoft provides an example of this in their article COM Interop Part 1: Client Tutorial: // Create an instance of a COM coclass: FilgraphManager graphManager = new FilgraphManager(); // See if it supports the IMediaControl COM interface. // Note that this will throw a System.InvalidCastException if // the cast fails. This is equivalent to QueryInterface for // COM objects:

Application hanging during CoCreateInstance of .NET-based COM object

痞子三分冷 提交于 2019-12-21 20:09:46
问题 I have a C++ DLL that is creating an instance of a COM object that's implemented in .NET. Under many circumstances this works fine, but under certain circumstances, it hangs the application, and I see it stuck with the following call stack (this is just the part underneath the level of my DLL's code): ntdll.dll!_NtAlpcSendWaitReceivePort@32() rpcrt4.dll!LRPC_CASSOCIATION::AlpcSendWaitReceivePort(unsigned long,struct _PORT_MESSAGE *,struct _ALPC_MESSAGE_ATTRIBUTES *,struct _PORT_MESSAGE *

Creating an instance of a COM interop class

六月ゝ 毕业季﹏ 提交于 2019-12-21 17:32:04
问题 I am trying to open CorelDRAW from within my program using C#. So far I have been able to do so by referencing the appropriate com library and calling CorelDRAW.Application draw = new CorelDRAW.Application(); draw.Visible = true; However, I would like my program to work with any version of CorelDRAW that supports interop. I am attempting to use reflection to load the interop library at runtime, where the specific dll can be chosen for the correct version. From looking around I have tried the

Understand COM c# interfaces

随声附和 提交于 2019-12-21 13:36:42
问题 The Microsoft.Office.Interop.Word._Document interface has a method with the following signature: void Close(ref object SaveChanges = Type.Missing, ref object OriginalFormat = Type.Missing, ref object RouteDocument = Type.Missing); A few points I am having trouble understanding: A ref parameter cannot have a default value. A default value has to be a constant, and Type.Missing is not. When calling this method, I can use Close(false) - normally a ref parameter requires an assignable variable?

Cannot get registration-free COM working from VBA

岁酱吖の 提交于 2019-12-21 12:12:04
问题 UPDATE: After spending 20+ hours trying to get a simple example working, I have realized that this is not as simple as it seems. Articles like this reveal the "gotchas" - and this was written before Windows 7 (which handles manifests differently). I'm sticking with exposing .NET assemblies to VBA via VSTO. I made a simple COM-Visible .NET assembly and am trying to call it from Excel VBA. If I "Register for COM Interop" during my .NET build, I can call it from VBA successfully. Sub VBA() Dim

Registration-Free COM Interop: Deactivating activation context in finalizer throws SEHException

大城市里の小女人 提交于 2019-12-20 04:26:18
问题 I am currently working on a mixed managed / native work chain and need to create an activation context for registration-free COM support (see Embed a Registration-Free COM manifest into a C# dll with native/managed environment). The following snippet is part of a larger class inside a C# DLL, which holds a reference to a COM Wrapper and establishes the required activation context: using System; using System.Runtime.InteropServices; using System.Diagnostics; namespace FirstClient { public