Create Out-Of-Process COM in C#/.Net?

We too had some issues many years ago with regasm and running the COM class as a Local EXE Server. This is a bit of a hack and I’d welcome any suggestions to make it more elegant. It was implemented for a project back in the .NET 1.0 days and has not been touched since … Read more

Access x86 COM from x64 .NET

If a component is running x64-native, it can’t load a 32-bit COM server in-process, because it’s the wrong sort of process. There are a couple of solutions possible: If you can, build a 64-bit version of the COM code (which would of course register itself in the 64-bit registry). This is the cleanest solution, but … Read more

Can’t get all excel processes to stop when closing through Powershell

For general guidance on how to release (Excel) COM objects, see the bottom section. $excel.Quit() is enough to eventually terminate the Excel process, but when that happens depends on when the garbage collector happens to run the next time. Your attempt to explicitly release Excel with [System.Runtime.InteropServices.Marshal]::ReleaseComObject($excel) is insufficient, because variables $script:workbook and $script:ws1 still … Read more

How to make make a .NET COM object apartment-threaded?

You can inherit from StandardOleMarshalObject or ServicedComponent for that effect: Managed objects that are exposed to COM behave as if they had aggregated the free-threaded marshaler. In other words, they can be called from any COM apartment in a free-threaded manner. The only managed objects that do not exhibit this free-threaded behavior are those objects … Read more

Exposing Property as Variant in .NET for Interop

COM Automation supports a default property, the property that has dispid 0. This is used in VB6 code to great effect, generating really compact code. A typical example is: rs!Customer = “foo” Which is syntax sugar for: rs.Fields.Item(“Customer”).Value = “foo” Three default properties being used here without being named in the original statement. The Recordset … Read more

What options are available for Shell32.Folder.GetDetailsOf(..,..)?

I figured this out by accident. If you pass null into GetDetailsOf then it responds with the column names. For example, execute the following JScript with cscript: var shellapp = WScript.CreateObject(“Shell.Application”); var folder = shellapp.NameSpace(“D:\\”); for (var j = 0; j < 0xFFFF; j++) { detail = folder.GetDetailsOf(null, j); if (!detail) { break; } WScript.Echo(“[” … Read more

Hosting the .NET runtime in a Delphi Program

In the Jedi Code Library (JCL) – free – there is a JclDotNet.pas, containing a class TJclClrHost, probably doing what you want: TJclClrHost = class(TJclClrBase, ICorRuntimeHost) private FDefaultInterface: ICorRuntimeHost; FAppDomains: TObjectList; procedure EnumAppDomains; function GetAppDomain(const Idx: Integer): TJclClrAppDomain; function GetAppDomainCount: Integer; function GetDefaultAppDomain: IJclClrAppDomain; function GetCurrentAppDomain: IJclClrAppDomain; protected function AddAppDomain(const AppDomain: TJclClrAppDomain): Integer; function RemoveAppDomain(const … Read more