interop

Safely disposing Excel interop objects in C#?

青春壹個敷衍的年華 提交于 2019-11-27 22:13:56
i am working on a winforms c# visual studio 2008 application. the app talks to excel files and i am using Microsoft.Office.Interop.Excel; to do this. i would like to know how can i make sure that the objects are released even when there is an error? here's my code: private void button1_Click(object sender, EventArgs e) { string myBigFile=""; OpenFileDialog openFileDialog1 = new OpenFileDialog(); DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. myBigFile=openFileDialog1.FileName; Excel.Application xlApp; Excel.Workbook

disabling overwrite existing file prompt in Microsoft office interop FileSaveAs method

☆樱花仙子☆ 提交于 2019-11-27 21:46:43
问题 I am using Ms Office Interop assemblies to create a MS Project file. To save the file created, I am using FileSaveAs method and it prompts a message saying that if you want to replace the existing file. I want to suppress the message, and I didn't find any parameter in FileSaveAs method for this purpose. Any Idea on this? I'am using C# as my programming language. 回答1: I ran into this issue when working with Excel Interop. The best I've been able to find is to disable all Office alerts, like

How to make a Swift String enum available in Objective-C?

家住魔仙堡 提交于 2019-11-27 21:46:20
I have this enum with String values, which will be used to tell an API method that logs to a server what kind of serverity a message has. I'm using Swift 1.2, so enums can be mapped to Objective-C @objc enum LogSeverity : String { case Debug = "DEBUG" case Info = "INFO" case Warn = "WARN" case Error = "ERROR" } I get the error @objc enum raw type String is not an integer type I haven't managed to find anywhere which says that only integers can be translated to Objective-C from Swift. Is this the case? If so, does anyone have any best-practice suggestion on how to make something like this

Call a Haskell function in .NET

给你一囗甜甜゛ 提交于 2019-11-27 21:42:17
问题 I want to use a Haskell function with the following type :: string -> string from a C# program. I want to use hs-dotnet to bridge both worlds. The author claim that it's possible, but provide no sample of this case. The only samples provided are the one to use .NET from Haskell. Is there a sample of this use, or how to use it? (I used .NET Reflector on the bridging assembly, but I didn't understand a thing.) 回答1: While your way works, it's worth noting that the dificulties you encountered

Registering a custom win32 window class from c#

久未见 提交于 2019-11-27 20:46:18
I have a new application written in WPF that needs to support an old API that allows it to receive a message that has been posted to a hidden window. Typically another application uses FindWindow to identify the hidden window using the name of its custom window class. 1) I assume to implement a custom window class I need to use old school win32 calls? My old c++ application used RegisterClass and CreateWindow to make the simplest possible invisible window. I believe I should be able to do the same all within c#. I don't want my project to have to compile any unmanaged code. I have tried

How to handle COM events from a console application?

扶醉桌前 提交于 2019-11-27 20:45:49
I'm using a COM object from a third party library that generates periodic events. When I use the library from a Winforms app, having the object as a class member and creating it in the main form thread, everything works. However, if I create the object from another thread, I don't receive any event. My guess is that I need to have some kind of event loop in the same thread used to create the object. I need to use this object from a console application. I guess I could use Application.DoEvents, but I'd rather not include the Winforms namespace in a console App. How can I solve this problem?

Handling events exposed on a .NET class via COM in VB6

醉酒当歌 提交于 2019-11-27 20:37:28
问题 Handling events exposed on a .NET class via COM in VB6 My test .NET (class libary registered for interop in compiler settings) code: Imports System.Runtime.InteropServices <InterfaceType(ComInterfaceType.InterfaceIsIDispatch), ComVisible(True)> _ Public Interface MyEventInterface <DispId(1)> Event Exploded(ByVal Text As String) <DispId(2)> Sub PushRedButton() End Interface <ClassInterface(ClassInterfaceType.None)> _ Public Class EventTest Implements MyEventInterface Public Event Exploded

Calling native libraries in Flutter using Platform Channels

徘徊边缘 提交于 2019-11-27 20:35:31
问题 Using platform channels, Flutter can interop with the native platform (i.e. reading battery level). On Android, this would require calling a Java method. I'd like to use a third-party Java SDK (for AWS Cognito). Can I put this library somewhere in my /android , and interact with it? If so, how can I do that? 回答1: If you haven't already got a plugin project started, create one. Gather the third party jars somewhere - don't put them in the pluginproject /android/... folder. Open the plugin

How to read an Excel spreadsheet in c# quickly

拈花ヽ惹草 提交于 2019-11-27 20:19:08
I am using Microsoft.Office.Interop.Excel to read a spreadsheet that is open in memory. gXlWs = (Microsoft.Office.Interop.Excel.Worksheet)gXlApp.ActiveWorkbook.ActiveSheet; int NumCols = 7; string[] Fields = new string[NumCols]; string input = null; int NumRow = 2; while (Convert.ToString(((Microsoft.Office.Interop.Excel.Range)gXlWs.Cells[NumRow, 1]).Value2) != null) { for (int c = 1; c <= NumCols; c++) { Fields[c-1] = Convert.ToString(((Microsoft.Office.Interop.Excel.Range)gXlWs.Cells[NumRow, c]).Value2); } NumRow++; //Do my other processing } I have 180,000 rows and this turns out be very

Convert from C++/CLI pointer to native C++ pointer

橙三吉。 提交于 2019-11-27 20:12:12
I have run in to this problem of converting a C++/CLI pointer to a native C++ pointer. Heres the background: I'm writing a windows forms application using C++/CLI. The application makes call into a number of COM Interfaces. When creating an instance (inside of a C++/CLR class) of a object through the COM interface, i pass in (void**)(&provider) as the last argument to CoCreateInstance , as in: HRESULT CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, (void**)(&provider)); However, i get the compiler error: cannot convert from cli::interior_ptr<Type> to void ** . I've done som research