com-interop

Using Wrapper objects to Properly clean up excel interop objects

佐手、 提交于 2019-12-04 01:21:29
All of these questions: Excel 2007 Hangs When Closing via .NET How to properly clean up Excel interop objects in C# How to properly clean up interop objects in C# struggle with the problem that C# does not release the Excel COM objects properly after using them. There are mainly two directions of working around this issue: Kill the Excel process when Excel is not used anymore. Take care to explicitly assign each COM object used to a variable first and to guarantee that eventually, Marshal.ReleaseComObject is executed on each. Some have stated that 2 is too tedious and there is always some

Signing my assembly with a strong name stops it from working

有些话、适合烂在心里 提交于 2019-12-04 01:10:53
A colleague of mine created an assembly in VB.net for use with JScript via COM interop. The assembly used to work fine, but we signed it and now it only seems to work on Windows 7 machines. I've tested 2 Windows 7 machines and 2 Windows Vista machines. When we signed the assembly and we try to instantiate the ActiveX object in JScript, an error is returned with no message and only a number: Error: Error number: -2146234304 A search on Google for the error number didn't return much. If we remove the strong name from the assembly, it works just fine. Any ideas on what could be the problem? Not

How to CreateObject in C#?

孤人 提交于 2019-12-03 23:34:05
问题 I want to translate the following VB6 code into C# If optHost(0).Value Then Set m_oScpiAccess = New IcSCPIActiveX.IcSCPIAccess Else sHost = txtHost.Text Set m_oScpiAccess = CreateObject("Exfo.IcSCPIActiveX.IcSCPIAccess", sHost) End If I used TlbImp.exe to create wrappers for the COM classes, and I tried: if (string.IsNullOrEmpty(host)) { // this works IcSCPIAccess = new IcSCPIAccess(); } else { // throws MissingMethodException IcSCPIAccess = (IcSCPIAccess)Activator.CreateInstance( typeof

Is it possible to register a .NET assembly for COM interop without adding registry entries?

冷暖自知 提交于 2019-12-03 20:57:16
问题 I am deploying a .NET VSTO application via click once. The application's main assembly needs to be registered for COM interop as part of the installation process. I know that this can be done by writing code to execute "REGASM assembly.dll /tlb", but the problem is that the target workstations that will be installing my application don't have administrative rights, so the regasm fails when trying to register the type library. My question is, how can I register my .net assembly for com

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

Using C#, how do I create a new Visual Studio 2012 Solution programmatically?

冷暖自知 提交于 2019-12-03 15:58:43
I followed this Stack Overflow post regarding how to create a project for VS2010, hoping that it would point me in the correct direction, but it doesn't cover creating a VS2012 project or solution. I also explored using SLNTools , but I don't see how to create a new solution from scratch. Ultimately, I would like to create 3-4 VS2012 projects programmatically and then add them to a solution which is also created programmatically. I attempted a solution based on this Stack Overflow post , but I get an odd error. Here is the code: Type typeDTE = Type.GetTypeFromProgID("VisualStudio.DTE.11.0");

How to mark .NET objects exposed to COM-interop as single threaded?

故事扮演 提交于 2019-12-03 14:00:58
When defining a COM-visible class in C++ I can define the supported threading model in the header file (the threading(single) line): [ coclass, default(IComInterface), threading(single), vi_progid("Example.ComClass"), progid("Example.ComClass.1"), version(1.0), uuid("72861DF5-4C77-43ec-A4DC-ED04396F0CCD") ] Is there a comparable way of setting the threading model in .NET (for example an attribute)? I currently define my COM-class as such: [Guid("67155A91-2948-43f5-B07F-5C55CDD240E5")] [ComVisible(true)] [InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface IComInterface { ... }

What does MethodImplAttribute(InternalCall, Runtime) do for methods of COM Interop interfaces?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 13:58:19
In Windows API Code Pack for .NET Framework , many methods of COM Interop interfaces are decorated with MethodImplAttribute , for example: internal interface IShellItem { [PreserveSig] [MethodImpl( MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] HResult BindToHandler( [In] IntPtr pbc, [In] ref Guid bhid, [In] ref Guid riid, [Out, MarshalAs(UnmanagedType.Interface)] out IShellFolder ppv); Documentation for MethodImplOptions.InternalCall value says: The call is internal, that is, it calls a method that is implemented within the common language runtime. Documentation for

How can I wrap a COM object in a native .NET class?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 12:19:50
问题 I'm using an extensive existing COM API (could be Outlook, but it's not) in .NET (C#). I've done this by adding a "COM Reference" in Visual Studio so all the "magic" is done behind the scenes (i.e., I don't have to manually run tlbimp ). While the COM API can now be "easily" used from .NET, it is not very .NET friendly. For example, there are no generics, events are strange, oddities like IPicture , etc. So, I'd like to create a native .NET API that is implemented using the existing COM API.

How to properly clean up Excel interop object in C#, 2012 edition

天涯浪子 提交于 2019-12-03 08:23:43
I am in the process of writing an application in C# which will open an Excel spreadsheet (2007, for now) via interop, do some magic, then close. The "magic" part is non-trivial, so this application will contain many references to many COM objects spawned by Excel. I have written this kind of application before (too many times, in fact) but I've never found a comfortable, "good smell" approach to interacting with COM objects. The problem is partly that, despite significant study, I still don't perfectly understand COM and partly that the interop wrappers hide much that probably shouldn't be