com-interop

COM->.NET - can't access overloaded method

百般思念 提交于 2019-12-31 03:50:22
问题 I'm trying to access a .Net library (The Image Resizer) from COM (jscript). I've tried both IDispatch and class interface generation, as well as [ClassInterface( ClassInterfaceType.AutoDual)] on the class in question. There is a method with 3 overloads: Bitmap Build(object, ResizeSettings settings) void Build(object source, object dest, string settings) void Build(object source, object dest, ResizeSettings settings) Calling Build("file",s); //works The following both generate "Wrong number of

Microsoft Interop saveAs command failed

五迷三道 提交于 2019-12-31 03:04:38
问题 I have this simple console app that converts Word documents to PDF using Microsoft Office Interop API. For some reason, this one document always fails and I have attached it and removed all extraneous content: click here For some reason, it works fine when you open the document and perform the saveAs function in Word, but through code, it fails. I've tried SaveAs2, SaveAs and ExportAsFixedFormat methods. I'm running Office 2010 and using Microsoft Word 14.0 Object Library. Thanks. My C# code

Excel interop - how to stop number (stored as text) being “evaluated”

霸气de小男生 提交于 2019-12-30 09:33:23
问题 I was wondering if anyone had come across the following problem and had any ideas on how to resolve it: I'm exporting data from a C# application (.NET 3.5) to Excel (2003) via Interop. One of the columns stores a string value that appears to be numeric. That is to say it is a number that begins with a 0 e.g. 000123 I need the full number to be stored as it may be a serial number or something similar. Excel is not keen on this so I thought I could get around it by setting the destination cell

Convention for passing BSTRs into COM functions from C# (COM interop)

巧了我就是萌 提交于 2019-12-30 08:19:06
问题 I am writing writing an API in COM in C++, and also writing a program which consumes this API in C#. My question is about BSTR memory management semantics when passing BSTRs into COM functions. Say my IDL looks like: HRESULT SomeFunction([in] BSTR input); Currently this function is implemented like this: HRESULT SomeFunction(BSTR input) { // Do stuff ..., then: SysFreeString(input); } When I call it from C# with something like SomeFunction(myString) , will C# generate something like this

.NET Interop: Find All instances of of a running COM object with C#

江枫思渺然 提交于 2019-12-30 07:03:08
问题 Background I am automating some Office application (Word and PowerPoint) via command-line tool. One thing my tool needs to do is locate all the running instances of Word. I know how to get a reference to one of the instances... Object running_obj = null; { running_obj = System.Runtime.InteropServices.Marshal.GetActiveObject(progid); } catch (System.Exception) { //failed to find the object; } if (running_obj!=null) { var running_obj_type = System.Type.GetTypeFromProgID(progid); Microsoft

How do I call a visual basic 6.0 method in c#?

杀马特。学长 韩版系。学妹 提交于 2019-12-29 08:46:10
问题 I would like to call a method which is written in visual basic 6.0 from c# (visual studio 2008). Is it possible? How would I do it? 回答1: Easiest way to do it is to just compile the VB6 code as an ActiveX DLL. Then you can reference the DLL in your .net project. (Visual studio can reference ActiveX DLLs properly.) 回答2: Compile your VB6 DLL as activex dll Register it using -> regsvr32 "Full Name And Path of newly compiled vb6 dll".(use Run Dialog or Command Prompt to register) In .net Add

Marshal.GetActiveObject() throws MK_E_UNAVAILABLE exception in C#

青春壹個敷衍的年華 提交于 2019-12-29 04:03:00
问题 The following vbscript code works prefectly fine: Dim App Set App = GetObject("","QuickTest.Application") App.Quit But when I translate it into C# code as below: class Program { [STAThread] static void Main(string[] args) { object qtApp = Marshal.GetActiveObject("QuickTest.Application"); (qtApp as QuickTest.Application).Quit(); } } I get the exception: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: (Exception from

C# Excel interop, put a line break in the text of a cell in a Excel

江枫思渺然 提交于 2019-12-29 01:35:18
问题 I am writing an Excel sheet using interop. In the sheet I need to put a set of sentences in to a cell. The text should be in a line break manner. How can I achieve this? Thanks in advance. 回答1: It was done by either entering "\r\n" or Environment.NewLine . And also must remember to make WrapText property true in order to make the line breaks visible. 回答2: you can add style to cells programically as bellow worksheet.Cells.Style.WrapText = true; 回答3: New line within an Excel cell is the LF

C# Excel interop, put a line break in the text of a cell in a Excel

孤人 提交于 2019-12-29 01:35:10
问题 I am writing an Excel sheet using interop. In the sheet I need to put a set of sentences in to a cell. The text should be in a line break manner. How can I achieve this? Thanks in advance. 回答1: It was done by either entering "\r\n" or Environment.NewLine . And also must remember to make WrapText property true in order to make the line breaks visible. 回答2: you can add style to cells programically as bellow worksheet.Cells.Style.WrapText = true; 回答3: New line within an Excel cell is the LF

Exposing Property as Variant in .NET for Interop

时光毁灭记忆、已成空白 提交于 2019-12-28 02:53:11
问题 I am creating a wrapper class in .NET (VB.NET as it happens but is equally related to C#) that is exposed to COM and one of the properties I am trying to wrap is a Variant. I thought I would just be able to use an Object, but I get an error: Public Property FieldValue([vFieldID As Object = -1]) As Object cannot be exposed to COM as a property 'Let'. You will not be able to assign non-object values (such as numbers or strings) to this property from Visual Basic 6.0 using a 'Let' statement.* My