rcw

How would I make garbage collection clean up RCW objects bound to an out-proc COM server?

我是研究僧i 提交于 2020-01-15 15:30:50
问题 I have a 64-bit .NET process that runs for days. The process consumes a native 32-bit COM server using DCOM. Once in a while the COM server runs out of memory because the .NET process garbage collector only sees the RCWs of the COM objects and those are quite lightweight and "not worth collecting". I need to somehow make garbage collector aware of those COM objects. For the record, I tried to run the same code periodically force-starting garbage collection and the problem goes away so the

Closing Excel Workbook - System.Runtime.InteropServices.COMException : Exception from HRESULT: 0x800A03EC

百般思念 提交于 2020-01-05 05:30:14
问题 I've put in the following method that returns a value from an XLS file cell : public static string ReadFromExcel(string filePath, int sheetNum, int xCell, int yCell) { List<string> rowValue = new List<string> {}; var ExcelFilePath = @filePath; Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(ExcelFilePath); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[sheetNum]; Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows

What is the difference between a COM string (BSTR) and a .NET string?

穿精又带淫゛_ 提交于 2019-12-22 06:36:22
问题 Is it just the way the bytes are combined to "encode" the data? I'm curious because I wonder how an RCW automatically takes a .NET string and transforms it into a COM BSTR. I'm guessing it just forms a valid COM BSTR transformed from the .NET string. Related: Could I construct my own valid BSTR using a byte type in .NET? 回答1: The two string types are not related at all. A transformation has to occur to convert one type to another. A BSTR has a number of conventions that must be followed in

C# wrapper interface error: E_NOINTERFACE

主宰稳场 提交于 2019-12-17 19:25:21
问题 I am trying to produce a C# wrapper for a COM object that I have (named SC_COM.dll), but am having some issues linking it with Visual Studio 2008 (running Vista). I need to do this registration-free with the COM DLL--I'm using a manifest file to let Visual Studio know about SC_COM.dll, and that appears to be working. I used TblImp.exe to generate a type library (SC_COMtlb.dll) that I'm referencing in Visual Studio 2008 so I can do early binding with the DLL that I need. The DLLs are both in

RCW & reference counting when using COM interop in C#

↘锁芯ラ 提交于 2019-12-17 15:26:02
问题 I have an application that uses Office interop assemblies. I am aware about the "Runtime Callable Wrapper (RCW)" managed by the runtime. But I am not very sure how the reference count gets incremented. MSDN says, RCW keeps just one reference to the wrapped COM object regardless of the number of managed clients calling it. If I understand it correctly, on the following example, using Microsoft.Office.Interop.Word; static void Foo(Application wrd) { /* .... */ } static void Main(string[] args)

VS2010 will not display project properties (“underlying RCW”)?

烈酒焚心 提交于 2019-12-10 14:58:31
问题 Only sometimes (I haven't yet noticed a pattern), VS2010 shows the following error (where I'd expect the body of the property page to be) when I right-click on a project (various types of projects) and select "Properties": I can typically view the project pages after restarting VS2010. I'm using the RTM version. What can cause this error? 回答1: LepardUK. I had the same issue and finally found out what had gone wrong. It's misbehaving addin - TestDriven.NET. But things could be different for

How to get the System.Type of a Runtime Callable Wrapper class from its CLSID?

纵然是瞬间 提交于 2019-12-10 06:21:26
问题 Note: For background information please see this related question: How to get LINQPad to Dump() System.__ComObject references? I am able to retrieve the CLSID of the RCW class corresponding to a COM object (obtained from another COM object, not initialized by my code) using IPersist.GetClassID(). Type.GetTypeFromCLSID() always returns the weakly-typed System.__ComObject , not the strongly-typed RCW class. I need to get the System.Type of the strongly-typed RCW class to be able to wrap the COM

How to get the System.Type of a Runtime Callable Wrapper class from its CLSID?

你。 提交于 2019-12-05 15:11:30
Note: For background information please see this related question: How to get LINQPad to Dump() System.__ComObject references? I am able to retrieve the CLSID of the RCW class corresponding to a COM object (obtained from another COM object, not initialized by my code) using IPersist.GetClassID() . Type.GetTypeFromCLSID() always returns the weakly-typed System.__ComObject , not the strongly-typed RCW class. I need to get the System.Type of the strongly-typed RCW class to be able to wrap the COM object with it using Marshal.CreateWrapperOfType() . Is this possible or is this a non-starter due to

What is the difference between a COM string (BSTR) and a .NET string?

陌路散爱 提交于 2019-12-05 11:40:15
Is it just the way the bytes are combined to "encode" the data? I'm curious because I wonder how an RCW automatically takes a .NET string and transforms it into a COM BSTR. I'm guessing it just forms a valid COM BSTR transformed from the .NET string. Related: Could I construct my own valid BSTR using a byte type in .NET? The two string types are not related at all. A transformation has to occur to convert one type to another. A BSTR has a number of conventions that must be followed in including allocated via SysAllocString*, deallocated with SysFreeString, having a length prefix, and a

How to get LINQPad to Dump() System.__ComObject references?

偶尔善良 提交于 2019-12-03 20:54:39
问题 I am playing around with using LINQPad to rapidly develop small ArcObjects (a COM-based library for ESRI's ArcGIS software) applications and have had some success in using it to Dump() the properties of COM objects that I initialize from .NET, but any COM objects that are obtained from an existing COM object are simply dumped as System.__ComObject references, which is not particularly useful: This help topic explains why this is happening, which I think I understand, but would like to know