com-interop

How can I invoke a static method on a .NET object over COM interop?

自作多情 提交于 2019-11-28 13:16:55
Is it possible to invoke a static method on a .NET Object, via COM interop? I know I could write a wrapper class. What if I don't wanna do that? No you cannot do this. COM interop communicates via objects, not types. Work arounds I know of ... The best work around is to create a wrapper method on an instance to do the call on the type. Yes this still requires an instance so it defeats the purpose but it's you're best option. Reverse PInvoke: Still requires you to pass a function pointer down to the C++ layer 来源: https://stackoverflow.com/questions/1395897/how-can-i-invoke-a-static-method-on-a

CoInitialize() / CoUninitialize() calls pairing

霸气de小男生 提交于 2019-11-28 11:46:29
问题 I have a single-threaded application that uses COM objects. At the beginning I in effect call CoInitialize(0) twice - once in my code and the second time in the code of another subsystem of the application. The first call returns S_OK , the second returns S_FALSE - exactly as MSDN says. When the application stops it calls CoUninitialize() twice but between those calls it tries to call methods of some COM objects - those calls just crash with access violation because I suppose the COM objects

Exposing the indexer / default property via COM Interop

∥☆過路亽.° 提交于 2019-11-28 11:37:49
I am attempting to write a component in C# to be consumed by classic ASP that allows me to access the indexer of the component (aka default property). For example: C# component: public class MyCollection { public string this[string key] { get { /* return the value associated with key */ } } public void Add(string key, string value) { /* add a new element */ } } ASP consumer: Dim collection Set collection = Server.CreateObject("MyCollection ") Call collection.Add("key", "value") Response.Write(collection("key")) ' should print "value" Is there an attribute I need to set, do I need to implement

In Excel VBA how to persist key variables over a 'state loss' (without writing to a cell or a file)?

那年仲夏 提交于 2019-11-28 11:33:35
Excel VBA is a flexible development environment. It is pesudo-compiled. However, sometimes during development a "state loss" can occur. A "state loss" is when all variables are torn down. Indeed, VBA has an option "Notify before state loss" option for triage. It is unsurprising that one cannot Edit and Continue code in all cases. However, sometimes state losses happen whilst running in production because opening some other workbook may cause trauma to your application session (trust me, it happens!) I know one can persist data to a worksheet cell or even a file but this is inappropriate for

WebBrowserSite: how to call a private COM interface method in a derived class?

妖精的绣舞 提交于 2019-11-28 10:07:19
Here is the challenge. I'm deriving from the Framework's WebBrowserSite class. An instance of my derived class, ImprovedWebBrowserSite , is returned via WebBrowser.CreateWebBrowserSiteBase , which I override in my derived version of the WebBrowser class - specifically to provide a custom site object. The Framework's WebBrowser implementation further passes it to down to the underlying unmanaged WebBrowser ActiveX control. So far, I've managed to override IDocHostUIHandler in my ImprovedWebBrowserSite implementation (like this ). I'm now looking for more core COM interfaces, like IOleClientSite

Setting up a DLL for registration-free COM Interop with C# / Managed code

落花浮王杯 提交于 2019-11-28 10:04:02
问题 I am new to COM and have to create a COM wrapper for a C++ dll, to make some functionality in it accessible for managed code. I mainly followed this tutorial on code project to create a COM ATL dll. I created a post-build-step that calls tlbimp.exe on the COM dll to create the wrapping. Adding a reference to the dll that tlbimp.exe creates works, and I get code completion for methods on my COM dll, and can compile managed code that uses that dll. However, running that code leads to the

Can't instantiate a COM object written in C# from VBA (VB6 ok)

纵饮孤独 提交于 2019-11-28 08:33:16
Using VS 2008, here is my COM object using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace TestCom { [Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123E")] [ClassInterface(ClassInterfaceType.AutoDual)] [ProgId("Test9.COMINT")] public class TestComClass { public void Init(string userid, string password) { MessageBox.Show(string.Format("{0}/{1}", userid, password)); } } } If I build this and register it on a production machine as follows REGASM /CODEBASE TESTCOM.DLL From a simple VB6 app this works fine Private Sub

.NET and COM Interoperability : release COM from .NET client

空扰寡人 提交于 2019-11-28 07:39:29
问题 Assume I have a COM object (unmanaged) and .NET Client. Is it necessary to call from the .NET client Marshal.FinalReleaseComObject method in order to release the COM object? 回答1: No. There is no need to explicitly release a COM object from a .Net client. The COM object will be collected like any other .Net object and will release it's underlying native handle once all references to it are removed. Explicit use of FinalReleaseComObject can actually lead to programming errors. If another

Is it possible to intercept (or be aware of) COM Reference counting on CLR objects exposed to COM

﹥>﹥吖頭↗ 提交于 2019-11-28 04:45:42
I have rephrased this question. When .net objects are exposed to COM Clients through COM iterop, a CCW ( COM Callable Wrapper ) is created, this sits between the COM Client and the Managed .net object. In the COM world, objects keep a count of the number of references that other objects have to it. Objects are deleted/freed/collected when that reference count goes to Zero. This means that COM Object termination is deterministic (we use Using/IDispose in .net for deterministic termination, object finalizers are non deterministic). Each CCW is a COM object, and it is reference counted like any

Activator.CreateInstance(<guid>) works inside VSIDE but not externally

爷,独闯天下 提交于 2019-11-28 03:52:14
问题 I have a bunch of COM objects which all implement the same interface, and need to create one of them as chosen at runtime from a list of options. Since I know the CLSID for each of the implementing COM servers, this should be easy. However, for a certain subset of COM libraries, I can only make this work if I'm running inside of the VS2010 IDE. Here is the entire program I'm using to test with: using System; namespace ComTest { class Program { static void Main(string[] args) { var clsid = "