com-interop

How can I generate C# source code for a COM Interop library instead of an assembly?

只谈情不闲聊 提交于 2019-12-10 15:49:44
问题 When importing a COM library (either directly with tlbimp, or indirectly with visual studio add reference dialog,) is there a way to generate C# source code instead of a binary interop assembly, like Interop.Word.dll, for example? UPD: Reflector is bad idea. Problem is that for the com interface is not only a signature, but the order of the members. Reflector this order is violated 回答1: I would go ahead and generate the interop assembly using TLBIMP, and the use Reflector to disassemble it.

Can't instantiate COM component in C# - error 80070002

自古美人都是妖i 提交于 2019-12-10 15:30:33
问题 I'm attempting to instantiate a Windows Media Player COM object on my machine: Guid mediaPlayerClassId = new Guid("47ac3c2f-7033-4d47-ae81-9c94e566c4cc"); Type mediaPlayerType = Type.GetTypeFromCLSID(mediaPlayerClassId); Activator.CreateInstance(mediaPlayerType); // <-- this line throws When executing that last line, I get the following error: System.IO.FileNotFoundException was caught Message="Retrieving the COM class factory for component with CLSID {47AC3C2F-7033-4D47-AE81-9C94E566C4CC}

Instantiating a COM Component fails with “Class not registered” when “Run As Administrator”

旧巷老猫 提交于 2019-12-10 15:24:37
问题 When instantiating a COM Interop object: var comObj = new ComComponentClass(); I get the COMException : Retrieving the COM class factory for component with CLSID {C343ED84-A129-11D3-B799-0060B0F159EF} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). I only get this error when I launch my application with Run as Administrator . When I run normally, the error does not occur. Notes: The application is 64-bit application.

How To Expose a DIctionary<> to COM Interop

蓝咒 提交于 2019-12-10 15:18:10
问题 I have an Interface that is defined something along these lines: Interface foo { int someProperty {get; set;} Dictionary<string, object> Items; } The concrete class that implements this interface needs to be registered for COM Interop. Everything compiles and the assemblies seem to register OK, but then when trying to create the COM object (e.g. from PowerShell) I get an error. This seems to be related to the generic Dictionary<> class that I'm using. So here is the question: Is it even

Hosting Microsoft Office application inside Silverlight 4?

非 Y 不嫁゛ 提交于 2019-12-10 14:10:42
问题 I know that Silverlight 4 has support for COM interop via the AutomationFactory class. dynamic excel = AutomationFactory.CreateObject( "Excel.Application" ); excel.Visible = true; But this creates a separate window for the COM object. What I am missing here is if I am actually able to actually host an Office document inside my Silverlight application - in a ContentPresenter for example? 回答1: You're not missing anything - it can't be done. You could look for converters to Silverlight of Office

Excel Interop: Range.FormatConditions.Add throws MissingMethodException

南楼画角 提交于 2019-12-10 11:21:07
问题 I am writing an application which uses the Microsoft.Office.Interop.Excel assembly to export/import data from Excel spreadsheets. Everything was going fine (except for 1 based indexing and all those optional parameters!), until I tried to use conditional formatting. When I call Range.FormatConditions.Add I get a MissingMethodException telling me that no such method exists. This happens in both Vista and XP. Here's an example of the code that generates the exception: //1. Add a reference to

How to get the System.Type of a Runtime Callable Wrapper class from its CLSID?

纵然是瞬间 提交于 2019-12-10 06:21:26
问题 Note: For background information please see this related question: How to get LINQPad to Dump() System.__ComObject references? I am able to retrieve the CLSID of the RCW class corresponding to a COM object (obtained from another COM object, not initialized by my code) using IPersist.GetClassID(). Type.GetTypeFromCLSID() always returns the weakly-typed System.__ComObject , not the strongly-typed RCW class. I need to get the System.Type of the strongly-typed RCW class to be able to wrap the COM

What's the difference between Marshal.GenerateGuidForType(Type) and Type.GUID?

丶灬走出姿态 提交于 2019-12-10 04:31:07
问题 Type classType = typeof(SomeClass); bool equal = Marshal.GenerateGuidForType(classType) == classType.GUID; I haven't found a case that fail this condition. So why and when should I use the Marshal method instead of simply getting the GUID property? 回答1: see http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.generateguidfortype.aspx ... GenerateGuidForType provides the same functionality as the Type.GUID property. So according to documentation they are the same.

Should I deploy Interop.x.dll files with .NET application?

落花浮王杯 提交于 2019-12-10 02:28:29
问题 We have a .NET app that consumes COM-objects in different DLLs, also used in the VB6 part of our app. When referencing a COM library, Visual Studio 2012 creates an Interop.x.DLL and references that instead. Should I be distributing Interop.x.DLL from the build machine or regenerating it using some .NET command-line tool? What tool? What is the best practice for deploying a .NET app that references COM? 回答1: No, that is not necessary anymore since VS2010 and .NET 4.0. You simply set the Embed

Troubleshooting an x64 com interop marshaling issue

风流意气都作罢 提交于 2019-12-10 00:28:38
问题 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