com-interop

Is it possible to test a COM-exposed assembly from .NET?

谁说我不能喝 提交于 2019-12-17 22:44:05
问题 I have a .NET assembly which I have exposed to COM via a tlb file, and an installer which registers the tlb. I have manually checked that the installer works correctly and that COM clients can access the library. So far, so good... However, I am trying to put together some automated system tests which check that the installer is working correctly. As part of that I have automated the installation on a VM, and I now want to make some calls to the installed COM library to verify that it is

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

本小妞迷上赌 提交于 2019-12-17 09:48:05
问题 .NET objects are free-threaded by default. If marshaled to another thread via COM, they always get marshaled to themselves, regardless of whether the creator thread was STA or not, and regardless of their ThreadingModel registry value. I suspect, they aggregate the Free Threaded Marshaler (more details about COM threading could be found here). I want to make my .NET COM object use the standard COM marshaller proxy when marshaled to another thread. The problem: using System; using System

What does “Register for COM Interop” actually do?

荒凉一梦 提交于 2019-12-17 09:43:09
问题 What exactly does the VS project option "Register for COM interop" actually do? Because when I build my library with this option enabled I can call CreateObject on my library from VBScript. But if I build without this and then run regasm manually CreateObject fails. So I'm wondering -- what does VS2010 do that I'm not doing? 回答1: It does the same thing as running Regasm.exe with the /tlb and /codebase options. The /codebase option is probably the one you forgot. Regasm likes assuming you put

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

醉酒当歌 提交于 2019-12-17 09:15:30
问题 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

Failed to cast result of Marshal.GetActiveObject for COM interop wrapper

江枫思渺然 提交于 2019-12-13 21:50:26
问题 I'm struggling to work out how to access a COM interface provided by a C++ application and use it from a C# .NET application. I try to access my COM object (which is provided by a running process) from my C# app like this: object obj = Marshal.GetActiveObject("MyLibrary.Application"); MyLibrary.IMainApp app = (MyLibrary.IMainApp)obj; The value of obj is non-null, but when I try to cast it I get System.InvalidCastException . I tried implementing a custom wrapper and also linked against a DLL

How can I call System.Runtime.InteropServices.Marshal.ReleaseComObject from within an Excel 2007 VBA module

六月ゝ 毕业季﹏ 提交于 2019-12-13 19:11:27
问题 I want to call System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) on some 3rd party COM objects that I've instantiated in my VBA code, from my workbook close event, something like the following: Public Sub disconnect(obj As Variant) Dim refs As Long refs = 0 If Not obj Is Nothing Then Do refs = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) Loop While (refs > 0) End If End Sub However, I get a compile error: invalid qualifier with the System highlighted with the above

COM Visible Assembly - Object method not accessible through its exposed interface method

守給你的承諾、 提交于 2019-12-13 16:21:20
问题 I implemented a .NET DLL with COM visibility (VB.NET): Public Class Processer Implements IProcesser Public Sub processASpecificThing(ByVal param As String) _ Implements IProcesser.processAThing ' [...] End Sub End Class Below the Interface definition. For some reasons I exposed a method with a different name in the interface. Imports System.Runtime.InteropServices Imports System.ComponentModel <InterfaceType(ComInterfaceType.InterfaceIsDual)> _ Public Interface IProcesser Sub processAThing

Consuming COM-object from C# console-project

不问归期 提交于 2019-12-13 14:09:50
问题 I have a problem consuming a COM-class from C#. The COM-class is developed in C++ ATL 32-bit. The COM-class works fine when i use it from VBA, VB6, C++, Javascript and even from MSTest/C# The wierd thing is that when i create an instance from a NUnit-test or from a Console application it fails with the exception: System.InvalidCastException : Unable to cast COM object of type 'PvtsFlashLib.FlashClass' to interface type 'PvtsFlashLib.IFlash4'. This operation failed because the QueryInterface

ActiveX component can't create object when using .net class in vba

余生长醉 提交于 2019-12-13 09:07:00
问题 I am trying to use a custom class exported as a .tlb in vba. I have done the regasm stuff but I keep getting this error when I try to call a subroutine within the class: Run-time error '429': ActiveX component can't create object I've referenced the class in vba, I've built the class for 32bit and 64bit CPUs and nothing worked. Anyways, vba code: Sub test() Dim test As New Mail.Class1 test.test End Sub And the vb.net code: Imports System.Runtime.InteropServices Public Class Class1 Public Sub

C# Outlook - How can I get the cursor position in the subject field of a MailItem?

放肆的年华 提交于 2019-12-13 02:36:51
问题 I want to insert a text at the current cursor position in the subject field of a MailItem in my C# AddIn. I additionally must know if the cursor is in the subject field. Does anyone know how to resolve it? EDIT To clearify what I want to do: With the Message my AddIn opens a WPF Window, where the user can select one of a couple of tags (e.g. "{stuff}"). If the user hits the insert button in the WPF window, the AddIn must insert the tag at the current cursor position. Actually I can just