interop

Excel file operations using interop in multithreaded C# application fails

人走茶凉 提交于 2019-12-06 22:53:36
I've an application that automates some file related jobs. Every job is executed inside separate threads. One kind of job is exporting an Excel file to HTML format. I use Microsoft.Office.Interop.Excel namespace for this purpose. My application was working fine under Windows Server 2008 environment but we upgraded our server to Windows Server 2012 and I started to get the following error : The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)) The thing is first call to export function successfully exports Excel file to

How to pass string parameters between C++ and C#?

随声附和 提交于 2019-12-06 22:49:31
I have imported a C++ library in my C# project. I can get the answer of a C++ method that has no parameters. What I want to do is to send some string parameters to C++ and get the result of it. In C++: public String SomeMethod(String param1, String param2) { //Some code } In C#: [DllImport("Library Path")] public static extern string SomeMethod(string param1, string param2); How can I do this? For strings that are input parameters passed from C# to C++, you could just use LPCWSTR (i.e. const wchar_t* ) at the interface on the C++ side, and marshal using the UnmanagedType.LPWstr option on the C

How to read an .RTF file using .NET 4.0

给你一囗甜甜゛ 提交于 2019-12-06 20:33:06
问题 I have seen samples using Word 9.0 object library. But I have Office 2010 Beta and .NET 4.0 in VS2010. Any tips on how to go with the new Word Dlls? So I just wanted to get the functionality of RTF to TEXT with .NET3.5 or later. 回答1: I got a better solution with WPF , using TextRange. FlowDocument document = new FlowDocument(); //Read the file stream to a Byte array 'data' TextRange txtRange = null; using (MemoryStream stream = new MemoryStream(data)) { // create a TextRange around the entire

Why can't set cast an object from Excel interop?

邮差的信 提交于 2019-12-06 20:25:31
问题 Trying to get a reference to the worksheets (using Excel interop): Excel.Application xl = new Excel.ApplicationClass(); Excel.Workbooks xlWorkBooks = xl.Workbooks; Excel.Workbook xlWorkBook = xlWorkBooks.Open(fileName, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); // Next line crashes Excel.Worksheets xlWorkSheets = (Excel.Worksheets) xlWorkBook.Worksheets; The error is that it cannot cast it: Unable to cast COM object of type 'System.__ComObject'

Is there a way to release unmanaged resources when a Go struct is collected?

社会主义新天地 提交于 2019-12-06 18:53:40
问题 I have a pointer to a C type wrapped by a Go struct, like so: type Wrapper struct { unmanaged *C.my_c_type } The C type, in turn, has the following functions: my_c_type* make_c_type(); void free_c_type(my_c_type *ct); Is there a way that I can ensure that free_c_type is called whenever a Wrapper instance is finalized? 回答1: You can use runtime.SetFinalizer. This allows you to run a cleanup function when the object falls out of scope. It is not guaranteed to run. However, when freeing memory,

Is it possible to expose a C# Enum to COM Interop callers, and if so, how?

感情迁移 提交于 2019-12-06 18:30:02
问题 I have a managed assembly that gets called via COM Interop. Like a VBScript client, a Perl client, and so on. The classes are decorated with [ClassInterface(ClassInterfaceType.AutoDual)] [GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")] [ComVisible(true)] Then of course I do the regasm thing, and all the methods work just fine. But there are also enum types in the assembly. I'd like to use symbolic names COM applications, for the enum values. How do I expose the enums via COM interop?

Calling COM visible managed component from managed code through COM wrapper

纵饮孤独 提交于 2019-12-06 17:15:14
问题 I have a 3rd party component, lets say FIPreviewHandler to handle preview, which implements IPreviewHandler. FIPreviewHandler is implemented as a Managed Component, and uses the IPreviewHandler interface and related interfaces through means of an interop. FIPreviewHandler is registered using regasm.exe as COM. I have a client application which is also Managed. I want to create an instance of FIPreviewHandler as a COM component in my application. I have an interop assembly that defines

How can I turn ON radio of a Wifi adapter that is actually OFF?

。_饼干妹妹 提交于 2019-12-06 16:04:01
I'm using Managed Wifi to get the radio state of my Wifi adapter. How can I turn the radio ON in case it is actually off ? Something like this : WlanClient wlanClient = new WlanClient() var targetInterface = wlanClient.Interfaces.FirstOrDefault() if (targetInterface != null) { bool radioIsOff = targetInterface .RadioState.PhyRadioState[0].dot11SoftwareRadioState == Wlan.Dot11RadioState.Off; if (radioIsOff) { // TODO } } I just added this to the WlanInterface class of the Managed Wifi API : IntPtr radioStatePtr = new IntPtr(0L); try { Wlan.WlanPhyRadioState radioState = new Wlan

SoapUI request to WCF service fails using certificates

荒凉一梦 提交于 2019-12-06 15:20:25
I have a custom binding like following for my WCF service which I am trying to call from the soapUI 4.5.1 <customBinding> <binding name="NewBinding0"> <transactionFlow /> <security authenticationMode="MutualCertificate" defaultAlgorithmSuite="Basic128" securityHeaderLayout="Lax" includeTimestamp="false" messageProtectionOrder="SignBeforeEncrypt" allowInsecureTransport="true" requireSignatureConfirmation="false" requireDerivedKeys="false" keyEntropyMode="ClientEntropy" requireSecurityContextCancellation="false" allowSerializedSigningTokenOnReply="true" messageSecurityVersion=

How to know which COM component is called by a certain PIA?

雨燕双飞 提交于 2019-12-06 15:18:11
I got a PIA installed on my box, it is Microsoft.mshtml . If I understandd it correctly, these PIA is provided by Microsoft to ease our life of COM interop. But I want to know which COM component is actually wrapped/called by this PIA. Because I am having a UnauthorizedAccessException, I want to locate the actual COM component and use dcomcnfg.exe to grant it proper permission. I hope this is the right direction. Thanks! It is c:\windows\system32\mshtml.dll. I seriously doubt that dcomcnfg.exe is going to solve your problem, this is an in-process COM server. You might get more insight by using