com-interop

COMException (0x80010108 - RPC_E_DISCONNECTED) When Closing Excel.Workbook

霸气de小男生 提交于 2019-12-06 00:25:45
When I run the following code, I get the exception below: ''# NOTE: ExcelApp is a Private main form variable Dim ReportBooks As Excel.Workbooks = ExcelApp.Workbooks Dim ReportBook As Excel.Workbook = ReportBooks.Open(localFilename) Dim ReportSheet As Excel.Worksheet = ReportBook.Sheets("Report") ''# Retreive data from sheet ReleaseCOM(ReportSheet) ReportBook.Close(True) ''# Error raised here ReleaseCOM(ReportBook) ReleaseCOM(ReportBooks) ERROR: COMException was unhandled The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)) Note: All

How to clean up COM references in .NET when app will be left running?

我与影子孤独终老i 提交于 2019-12-05 23:55:02
I am working on a .NET program that starts a new instance of Excel, does some work, then ends, but must leave Excel running. Later, when the program runs again, it will attempt to hook into the previous instance. What is the best way to handle the releasing of COM objects in this situation? If I do not do a "ReleaseComObject" on the app object the first time, then on the second run get the active object, then finally release the com object, do I have a memory leak? The following simplified code illustrates what I am trying to do: private Microsoft.Office.Interop.Excel.Application xlsApp;

Marshal.GetActiveObject(“Outlook.Application”) throws MK_E_UNAVAILABLE when debugging with elevated privileges

做~自己de王妃 提交于 2019-12-05 22:53:46
问题 This code run without problem in release r debug when Visual studio isn't started as an admin. Marshal.GetActiveObject("Outlook.Application"); However, when I start Vs as administrator and run the same line in debug, I get the following error: System.Runtime.InteropServices.COMException Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) How can I fix this. 回答1: I would guess that you are running Visual Studio as Administrator (started via Run as Administrator) while

COM Object Cleanup

◇◆丶佛笑我妖孽 提交于 2019-12-05 22:38:50
I am instantiating a COM object from a VBA script in excel as defined in a C# dll. The C# class I instantiate has a finalizer that performs garbage collection, notably other MS Office objects it references, which I should see appear and disappear in the task manager. In fact, the unit tests demonstrate that an Office process appears when the dll is called, and goes away when it is finished. When the dll is called from the VBA, I have noticed that the processes remain open after the VBA function ends, i.e. the object is notcleaned up after being called, which leads me to believe that VBA does

How can I manipulate a VB6 Collection in .NET?

孤者浪人 提交于 2019-12-05 21:48:17
I am currently in the process of designing an interface for .NET software that would be consumed by COM objects - specifically, VB6. While I have found a number of pages by Microsoft detailing how to make an COM-interoperable interface, I am currently tripping over the use of Collections in design time: I would like to be able to use a standard VB6 "Collection object" in the .NET program - that way, I would be able to specify, in the interface, such a collection as an argument, or as a return type, simplifying the work required for clients to use the interface. Thank you in advance. Edit: I

Problem creating COM-library only containing enum's

人盡茶涼 提交于 2019-12-05 20:33:19
I'm am doing a COM-interop project. Substituting some VB and C++ ATL COM projects with C# and .NET Interop. When i define enumerations in .NET and they are made ComVisible, they get exposed as Typelib.EnumType_EnumValue enstead of just Typelib.EnumValue. The typelib exporter does this to ensure that the value names are unique. But i know that all my enum's are unique, so i don't want the underscores. Also there is a lot of client code that needs alteration if i don't get rid of the underscores. To find a solution to this problem, i have defined the enum's in an IDL-file and creating a typelib

Trying to build a COM Component in C# that can be referenced and used from VB5/6

纵饮孤独 提交于 2019-12-05 20:11:48
I am trying to see if I can build a COM component in C# (.NET 4) which I can use from a VB5 program (cue derisive remarks) to access a web service. Following all the instructions I have been able to find on MSDN and CodeProject as follows: Building COM Objects in C# Example COM Class (C# Programming Guide) I have written the following: [Guid("7A715F02-D349-45DC-B0AE-9925FD3B943C")] public interface ARCOM_Interface { [DispId(1)] string GetServiceResponse(); } [Guid("5130F041-619E-41F9-84B6-8332642228F6") , InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface ARCOM_Events { }

How to get a reference to Internet Explorer's window handle in .net

狂风中的少年 提交于 2019-12-05 19:16:46
Basically I am trying to get the HWND of an instance of Internet Explorer that I have been automating in C#. SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer(); IE.AddressBar = false; IE.MenuBar = false; IE.OnQuit += IE_OnQuit; IE.Visible = true; IE.Navigate2("www.bing.com"); I would like to get a reference to it's window handle for further manipulation, however the only example of how to do this is in C++ and I am not sure how to do something similar in C#. The Example the msdn gave is here . Getting the HWND is as simple as: IntPtr hwnd = (IntPtr)IE.HWND; 来源: https://stackoverflow

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

.NET Core 2.1 - How to create COM object and generate *.tlb file

强颜欢笑 提交于 2019-12-05 10:51:28
I would like to build COM object in .net Core and then register by RegAsm. My .csproj file: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFrameworks>netcoreapp2.1;net4.7.2</TargetFrameworks> <RuntimeIdentifier>win7-x64</RuntimeIdentifier> <Platforms>x64</Platforms> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> </Project> My program.cs: using System; using System.Runtime.InteropServices; namespace ComExample { [Guid("7ce1e40f-760a-4d81-b70b-61108ed15cb4")] [ComVisible(true)] public interface IComExampleClass { IComModelClass