com-interop

COM Interop, RPC server is unavailable in c#

孤街醉人 提交于 2019-12-05 10:31:02
I am using a COM Interop and i am instantiating the COM class object from the interop dll So, few times the object is instantiated successfully and make remote procedure calls without any problem but sometimes it throws an exception like RPC Server is unavilable. The COM Component i am using is written in VB and i am consuming that component in c#. So, can anybody tell me the possible reasons for the problem(RPC Server is Unavailable) and solutions to this problem. I am helpless with this issue by now. So, Advance thanks if you can help me out After reviewing my approach for COM implementation

How to properly clean up interop objects in C#

偶尔善良 提交于 2019-12-05 10:26:54
This is a follow on question to How to properly clean up excel interop objects in c# . The gyst is that using a chaining calls together (eg. ExcelObject.Foo.Bar() ) within the Excel namespace prevents garbage collection for COM objects. Instead, one should explicitly create a reference to each COM object used, and explicitly release them using Marhsal.ReleaseComObject(). Is the behaviour of not releasing COM objects after a chained call specific to Excel COM objects only? Is it overkill to apply this kind of pattern whenever a COM object is in use? It's definitely more important to handle

What is the correct way to implement a Managed Property Handler Shell Extension?

☆樱花仙子☆ 提交于 2019-12-05 09:07:38
Now that .NET CLR 4.0 supports side by side (SxS) operation it should now be possible to write shell extensions in managed code. I have attempted this and successfully coded a Property Handler that implements IPropertyStore, IInitializeWithStream and IPropertyStoreCapabilities. The handler works fine and is called as expected when browsing files via the explorer. It also works fine in displaying the custom properties in the preview panel and the file properties "detail" panel. However, when I attempt to edit a property in the preview panel, and then click "Save" I get a "File In Use" error

Visual Studio 2010: Embed Interop Types

末鹿安然 提交于 2019-12-05 01:28:04
I found some information about this on Scott Hanselmans Blog Does anybody exactly know what this mean? Is this only for the Office Primary Interop Assemblies, or can I also use this to Embed my Redemption library or other COM libraries? The process described in Scott Hanselman's blog is called Type Equivalence , a rather nebulous term for the CLR 4.0's support for COM interop type assemblies. Although I haven't had a chance to look at it, there is a video here at Channel 9 that discusses it: Raja Krishnaswamy and Vance Morrison: CLR 4 - Inside Type Equivalence http://channel9.msdn.com/shows

What does MethodImplAttribute(InternalCall, Runtime) do for methods of COM Interop interfaces?

两盒软妹~` 提交于 2019-12-04 20:23:01
问题 In Windows API Code Pack for .NET Framework, many methods of COM Interop interfaces are decorated with MethodImplAttribute , for example: internal interface IShellItem { [PreserveSig] [MethodImpl( MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] HResult BindToHandler( [In] IntPtr pbc, [In] ref Guid bhid, [In] ref Guid riid, [Out, MarshalAs(UnmanagedType.Interface)] out IShellFolder ppv); Documentation for MethodImplOptions.InternalCall value says: The call is internal

Troubleshooting an x64 com interop marshaling issue

送分小仙女□ 提交于 2019-12-04 19:38:28
I have a C++ COM Server which I have recently recompiled to 64 bit. This COM server has a method that contains a struct parameter which contains some ints and a BSTR and another structure. Now, I am trying to call this COM server from a 64 bit .Net C# application. I can successfully load my COM server and call this method as long as I don't try to populate any of the string parameters. If I try to pass valid values in the int members, they end up corrupted by the time the end up at the COM object implementation. It appears as though the way the structure is marshaled is just wrong. This code

Returning Multiple Results (UDT?) From An Interop Call - VB6 <--> VB.NET

冷暖自知 提交于 2019-12-04 19:24:33
I’d like an Interop user control (VB.NET) to return and to accept multiple values from a get/set call. I assumed a user defined type (UDT), would be the correct way but I keep getting a “Variable uses an Automation type not supported in Visual Basic” from the VB6 compile. How is passing multiple values between an interop control and the VB6 application done? VB.NET (Interop) code, a control with a .NET ListView Structure Employee Dim Firstname As String Dim Lastname As String End Structure … Public Property MyReadListViewData() As Employee Get Dim myEmployee As Employee myEmployee.Lastname =

Exception handling: how granular would you go when it comes to argument validation?

試著忘記壹切 提交于 2019-12-04 19:20:53
I'm coding a simple little class with a single method send an email. My goal is to implement it in a legacy Visual Basic 6 project, exposing it as a COM object via the COM Interop facility. There's a detail I'm finding difficult to resolve, that being how granular should I be at validating parameters. On that light, a thing I'm really not happy about, and which is not a detail at all, is the way I'm actually handling exceptions: public class MyMailerClass { #region Creation public void SendMail(string from, string subject, string to, string body) { if (this.IsValidMessage(from, subject, to,

C# How do you get an instance of a COM interface

和自甴很熟 提交于 2019-12-04 17:18:19
I've been doing quite a bit of googling trying to find the standard way to get an instance of a COM interface. Microsoft provides an example of this in their article COM Interop Part 1: Client Tutorial : // Create an instance of a COM coclass: FilgraphManager graphManager = new FilgraphManager(); // See if it supports the IMediaControl COM interface. // Note that this will throw a System.InvalidCastException if // the cast fails. This is equivalent to QueryInterface for // COM objects: IMediaControl mc = (IMediaControl) graphManager; // Now you call a method on a COM interface: mc.Run();

Is it possible to forward delegate through COM interop?

妖精的绣舞 提交于 2019-12-04 16:37:09
I have a class: public class A { public delegate void SetTextDel(string value); public void Test() { SetTextDel setText = someInterface.SetText; icom.Set(setText); } } [ComVisible(true), Guid("81C99F84-AA95-41A5-868E-62FAC8FAC263"), InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface Icom { void Set(Delegate del); } [ComVisible(true)] [Guid("6DF6B926-8EB1-4333-827F-DD814B868097")] [ClassInterface(ClassInterfaceType.None)] [ComDefaultInterface(typeof(Icom))] public class B : Icom { Set(Delegate del) { del.DynamicInvoke("some text"); } } And I get targetinvocation exception in Set