com-interop

PowerShell: how to convert a COM object to an .NET interop type?

天大地大妈咪最大 提交于 2019-11-27 07:48:37
问题 As described in my question Create ISO image using PowerShell: how to save IStream to file?, in PowerShell I create an IStream object as follows: $is = (New-Object -ComObject IMAPI2FS.MsftFileSystemImage).CreateResultImage().ImageStream This object is of (PowerShell) type System.__ComObject . And somehow PowerShell knows that it is an IStream : PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IConnectionPoint] False PS C:\> $is -is [System.Runtime.InteropServices.ComTypes.IStream]

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

白昼怎懂夜的黑 提交于 2019-11-27 07:35:37
问题 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? 回答1: 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

Side-By-Side COM Interop with C# and VBA

假如想象 提交于 2019-11-27 07:20:51
I'm not talking about calling a VBA COM from C#... the other way around! What I would like to do is call a C# library using VBA in MS Access without registering the DLL. I've been playing around with side-by-side interop for a while without success and it has finally occurred to me that a mdb.manifest is probably not an acceptable replacement for an exe.manifest (probably obvious, I know, but I was trying to be optimistic). My question: Is it possible to get VBA to load a side-by-side COM component? Or, is there another way to use an unregistered C# library in Access? (Before you ask, my

Exposing the indexer / default property via COM Interop

老子叫甜甜 提交于 2019-11-27 06:29:48
问题 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

Hosting managed code and garbage collection

核能气质少年 提交于 2019-11-27 06:25:42
问题 I have a C++ out-of-process COM server that hosts a lot of C# code to support the API exposed by the C++ COM objects. For a variety of reasons, I am considering eliminating the C++ portion of my solution. However, because of constraints outside of my control I have to retain the out-of-process COM server. Microsoft does have a canonical example of this here. Looking at this example there is something I don't understand. Before the message loop starts, a timer is created to call GC.Collect

COM Interop without regasm

我的梦境 提交于 2019-11-27 05:33:47
问题 I'm a limited user, and I need to write an Outlook macro that exposes a C# library in Outlook 2003 and 2007. I do not have any admin privilges at all, not even at install time, so I can't run RegAsm and I can't (I assume) write a managed add-in. Is there any way to call .Net code from VBA in this scenario, or are there any other solutions? This is for personal use only, so an ugly hack is perfectly acceptable (so long as it works) 回答1: I solved this by running regasm with the /regfile option,

Compiling Quantlib via SWIG for C#

亡梦爱人 提交于 2019-11-27 04:32:13
问题 Anyone have any experience using SWIG? I am currently researching QuantLib and saw that C# code can be generated using SWIG. We are exploring options to create a combined library of financial functions using QuantLib and a proprietary closed source library (which will probably be made available as .Net dlls). The idea is to combine both of these to create a unified super library. I have seen the .Net port of QuantLib, but it seems that it is not actively maintained (and not entirely sure of

CoCreateInstance returning E_NOINTERFACE even though interface is found

给你一囗甜甜゛ 提交于 2019-11-27 04:31:28
问题 I have a COM class CMyCOMServer implementing IMyInterface in one application, both with correct GUIDs. CMyCOMServer::QueryInterface will return S_OK (and cast itself to the right type) if IUnknown or IMyInterface is requested, otherwise it returns E_NOINTERFACE. In another app on the same PC, I call: HRESULT hr = ::CoCreateInstance(__uuidof(CMyCOMServer), 0, CLSCTX_SERVER, __uuidof(IMyInterface ),(void **)&pInterface); It returns E_NOINTERFACE. So I assumed I was doing something wrong and

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

孤人 提交于 2019-11-27 03:30:01
问题 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

Cannot pass a GCHandle across AppDomains: solution without delegates?

浪子不回头ぞ 提交于 2019-11-27 02:51:50
问题 I have base library in c++ and client application is in C#. There is c++/cli interface to access c++ api's from C#. Every thing works fine until more than one app domain not come into play like NUnit or WCF hosting i.e. with one app domain. I have stored managed object in gcroot in cli for callback. I have read that this is the root cause of app domain issue ("Cannot pass a GCHandle across AppDomains") because they don't have app domain info (http://lambert.geek.nz/2007/05/29/unmanaged