com-interop

“Access to the Registry Key Denied” when building a .NET DLL for COM Interop

二次信任 提交于 2019-12-04 11:06:58
Objective : build a C# DLL with COM interop to be called by Delphi on another environment. Problem : Windows is blocking my build, saying that I don't have privileges to edit the registry. Context: I'm using Windows 8, Visual Studio 2012, UAC is turned off. I'm using RGiesecke's DllExport to annotate with [DllExport] the methods that I want to export as an Dll. I'm using [ComVisible(true)] as suggested here . My solution platform target is x86 I edited my solution's build propertires and checked Build > Output > Register for COM Interop I edited by AssemblyInfo.cs and enabled [assembly:

com4j versus jacob to call COM methods from Java

旧巷老猫 提交于 2019-12-04 11:05:53
问题 I maintain a legacy Java application that uses Jacob, or Java-COM Bridge, to make calls via the COM interfaces of MS VBA and MS Word. I have been looking at com4j from Sun, and it looks promising. The reason it looks good to me is that it uses vtable binding to methods, instead of IDispatch. Assuming all the COM objects we manipulate present vtable interfaces, it seems cleaner to use them instead of IDispatch. Back in the days when COM and CORBA where the hot binary interface technologies, I

Dynamically load and use COM object in C#

风流意气都作罢 提交于 2019-12-04 11:05:43
I have a C# project, where I would like to access MS outlook, if it is installed on a client´s machine. The "access outlook" part has been done by referencing the outlook COM object, and going from there. My problem is now the "if it is installed" part. At the moment, my project doesn´t compile on machines without outlook installed, so I assume that I will have to not reference the outlook component, and instead load and use it dynamically, after detecting that outlook is present, but I haven´t found a way to do this. Am I correct, and does anybody have any hints on how to do this? Thanks.

How to expose nullable types via COM

半腔热情 提交于 2019-12-04 10:51:05
问题 I have been struggling with this problem for a day and a half, hopefully someone can help me. Let's say I have structures like this in C#: public struct Part { public double? x; // or System.Nullable<double> x, doesn't really matter } (these structures represent database tables, converted from Linq to SQL code created by SQLMetal) I need to be able to expose these structures, containing nullable types, to COM so that they can be used in another application (C++). But I cannot figure out, for

Load a COM dll at runtime?

≡放荡痞女 提交于 2019-12-04 07:35:35
I'm writing an application for the Peachtree API and it needs to work with any version of the API. Unfortunately the dll from Peachtree 2011 can't interact with Peachtree 2010, and vice versa, even though the two dlls are stored in the same location and run with exactly the same code. I thought I should be able to refer to the dll by it's file path, leave specific version at false, embed interop types at false, and copy local at false and it would just use whatever version the machine had, but I get an error when I do that - "Exception has been thrown by the target of an invocation." Is there

Understand COM c# interfaces

谁说我不能喝 提交于 2019-12-04 05:52:56
The Microsoft.Office.Interop.Word._Document interface has a method with the following signature: void Close(ref object SaveChanges = Type.Missing, ref object OriginalFormat = Type.Missing, ref object RouteDocument = Type.Missing); A few points I am having trouble understanding: A ref parameter cannot have a default value. A default value has to be a constant, and Type.Missing is not. When calling this method, I can use Close(false) - normally a ref parameter requires an assignable variable? When navigating to the definition of Type in Visual Studio, it takes me to the _Document.Type property,

Reflection on COM Interop objects

别来无恙 提交于 2019-12-04 05:11:59
Trying to create a mapper for an Microsoft Office object to POCO's and found this // doesn't work // returns an empty array where o is a RCW on an office object foreach(var pi in o.GetType().GetProperties() ) tgt.SetValue(rc, pi.GetValue(o, null)); so have to resort to this foreach(var field in tgt.GetFields() ){ var pv = o.InvokeMember(field.Name, System.Reflection.BindingFlags.GetProperty, null, o, null); i.SetValue(rc, pv); } which works for now but wondering why the RCW.GetProperties() doesn't work here? The other two answers as of this writing are correct, but they miss an important

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

我的未来我决定 提交于 2019-12-04 04:36:54
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. I would guess that you are running Visual Studio as Administrator (started via Run as Administrator) while Outlook was opened as user, who was logged in as under Windows logon. So the Visual Studio is running under

Exposing c# anonymous class objects to COM (JavaScript)

℡╲_俬逩灬. 提交于 2019-12-04 04:07:50
问题 Is there a class/API in .NET 4.5+ allowing to expose an instance of C# anonymous class as as late-bound object to COM? E.g. I want do this: webBrowser.Document.InvokeScript("TestMethod", new object[] { new { helloProperty = "Hello!", byeProperty = "Bye!" } }); and use it in JavaScript: function TestMethod(obj) { alert(obj.helloProperty + ", " + obj.byeProperty); } It should not be a problem to create a helper class to wrap the anonymous object and expose its properties via IReflect, but

What is the Guid attribute that appears above classes in C#?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 02:47:16
问题 I've picked up some C# code recently and one of the classes has a Guid attribute present above it. I don't understand what this is or what it's used for. Can someone give me a rundown of what it is, or just point me in the direction of some articles that give more information about this? Thanks! 回答1: It is the COM identifier that represents the class in question. The class is designed for COM interop. 回答2: You might want to take a look at the ComVisibleAttribute class to learn more about the