com-interop

.NET Core 2.1 - How to create COM object and generate *.tlb file

霸气de小男生 提交于 2019-12-07 06:12:04
问题 I would like to build COM object in .net Core and then register by RegAsm. My .csproj file: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFrameworks>netcoreapp2.1;net4.7.2</TargetFrameworks> <RuntimeIdentifier>win7-x64</RuntimeIdentifier> <Platforms>x64</Platforms> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> </Project> My program.cs: using System; using System.Runtime.InteropServices; namespace ComExample { [Guid("7ce1e40f-760a

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

这一生的挚爱 提交于 2019-12-07 05:25: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

Opening Word-document (.doc) using C# causes COMException due to File Block Settings

会有一股神秘感。 提交于 2019-12-07 05:23:40
问题 I'm trying to open a really old (binary) Word-file using C#/.NET and Microsoft.Office.Interop.Word. Whenever I try to open this file using the snippet below, it fails with a COMException telling me that "You are attempting to open a file type that is blocked by your File Block settings in the Trust Center." This also used to happen when opening the same file in MS Word, but after adjusting the settings found in the Trust Center this now works just fine. However, I still cannot open the file

Where are the VBProjectsEvents?

倖福魔咒の 提交于 2019-12-07 04:40:52
问题 Using Microsoft.Vbe.Interop in C#, I can access CommandBarEvents and ReferencesEvents via VBE.Events . However the ever-so helpful MSDN documentation seems to indicate that there's a VBProjectsEvents that I could use to notify my add-in when a project is added or removed to/from the VBE... which is exactly what I'm trying to achieve here. I can see that _VBProjectsEvents interface in the object browser , but no implementation for it (as opposed to the _CommandBarControlsEvents interface,

delaying excel calculations during interop C#

自古美人都是妖i 提交于 2019-12-07 04:20:18
问题 I have to input several hundred cells into an excel sheet from a C# program. Each time I set a cell or a range, excel slowly responds... presumably updating various outputs between each input I add. Is there a way to disable calculations from my C# program, and re-enable it after I am done setting cells and ready to read the outputs? 回答1: Yes, set the Application.Calculation to xlCalculationManual , then back to xlCalculationAutomatic . You can also consider setting Application.ScreenUpdating

COM Interop .NET STA

主宰稳场 提交于 2019-12-07 04:14:15
问题 If I have an STA thread in .NET, and I create an STA COM object in that thread, and then the thread finishes -- does that kill that instance of the object? Is my understanding correct that STA COM objects can be accessed by multiple threads and runtime will automatically marshal the calls to all happen in the apartment thread? Is that thread the thread that has created the instance? So if that thread finishes, the instance is orphaned and lost? Or is there a separate thread created for STA

COM `HRESULT` is wrapped into an Exception in .NET

喜你入骨 提交于 2019-12-07 01:54:08
问题 (preliminary note: I'm not yet fully up to speed with the whole 'interop' thing...) When using a COM library from within .NET, all HRESULT methods are wrapped into something that throws when the return code is not SUCCEEDED. //ATL magic exluded class C { HRESULT foo(){ return E_FAIL; } }; // usage code: if( SUCCEEDED( c.foo() ) ) { // success code } else { // failure code } The .NET counterpart of this code reads: try { c.foo(); // success code } catch ( Exception e ) { // failure code } Is

Consuming VB6 string array in C#

我与影子孤独终老i 提交于 2019-12-06 22:22:39
问题 I have (legacy) VB6 code that I want to consume from C# code. This is somewhat similar to this question, but it refers to passing an array from VB6 consuming a C# dll. My problem is the opposite. In VB, there is an interface in one dll, and an implementation in another. Interface: [ odl, uuid(339D3BCB-A11F-4fba-B492-FEBDBC540D6F), version(1.0), dual, nonextensible, oleautomation, helpstring("Extended Post Interface.") ] interface IMyInterface : IDispatch { [id(...),helpstring("String array of

COM Interop with VB6 and C#

旧时模样 提交于 2019-12-06 16:24:08
I'm writing a C# COM object that will be used by a VB 6 program. That shouldn't be much of a problem, however, the VB6 call to the COM object passes in a VB Control (in this case a TextBox). The program expects the COM object to alter the Text property of the control. Unfortunately, I have to stick to this interface as I'm dealing with someone elses legacy code. How can I set the property for the passed in TextBox? Do I simply create an interface with a Text property and cast input to that interface? Is this even possible? Please let me know if I need to clarify. Note: I intended to leave out

Can Range.Value2 & Range.Formula have different values in C#, not VBA?

白昼怎懂夜的黑 提交于 2019-12-06 16:21:55
I want to create a UDF which is like GetPath(parameter) , where parameter can be a cell reference like "B1" , or a string what the GetPath does, based on input, it will call web service to get path for input e.g. formula of cell A1=GetPath(B1) , cell B1 has some string, the function should return path and put it in cell A1, i.e. "Value2" of A1 should be path of B1. Now in C#, when I did sth FormulaCell.Value2 = path , its formula changes, too but I want "Formula" & "Value2" to be different. I know this is possible in VBA, but I am using C#. Anyone knows how to accomplish this? thanks I googled