interop

Marshal a list of objects from VB6 to C#

I have a development which requires the passing of objects between a VB6 application and a C# class library. The objects are defined in the C# class library and are used as parameters for methods exposed by other classes in the same library. The objects all contain simple string/numeric properties and so marshaling has been relatively pa...

check if a sheet exists in excel

How do i check if a sheet exists in a excel using interop. I tried the following but it throws an COMException if not there.. Is there a better way of finding out than actually looking at the exception Worksheet sheet = null; Sheets worksheets = some; sheet = (Worksheet)worksheets.get_Item("sheetName"); if(sheet!=null)...

Invoke a COM addin option from VBA

Can I invoke an option on a COM Add-in from a VBA macro in Word or Excel 2007? The COM Add-in was written using VSTO – it adds a custom ribbon tab with a number of options that I want to execute from a VBA macro. I can reference the add-in using Application.COMAddIns("MyAddinName") but I can’t find an option to invoke an option. I’ve a...

Using TaskDialogIndirect in C#

I've been working for a while with the regular Windows Vista/7 TaskDialog for a while, and I wanted to add some additional functionality (like custom buttons and a footer), so I need to use TaskDialogIndirect. Following the MSDN documentation for TaskDialogIndirect, I got this signature: [DllImport("comctl32.dll",CharSet = CharSet.Unic...

How to upgrade a VB6 app with .NET components

I want to make a change to a VB6 app which consists of a .EXE, no VB6 DLLs but a handful of .NET DLLs. The interop is achieved by a one of the .NET dlls being referenced by the VB6 app which seems to require REGASM-ing of an associated .tlb file. If I want to change only the VB6 app .exe, could I just compile it and drop it into the ...

Does the COM server have to call SysFreeString() for an [out] parameter?

We have the following interface: [object, uuid("uuidhere"), dual ] interface IInterface : IDispatch { [id(1), propget] HRESULT CoolProperty( [out, retval] BSTR* result ); } Now there's a minor problem. On one hand the parameter is "out" and so any value can be passed as input, the parameter will become valid only upon the successf...

Making a COM dll to be invoked from c#, HRESULT error handling?

I'm making a COM interface that c# will be using, however i am wondering how i am to check for errors for exception handling on the c# end. As at the moment i am just returning a HRESTULT or bool for most methods and then doing a Marshal.ThrowExceptionForHR but several things can go wrong in some of these methods and returning a E_FAIL ...

How to pass a const unsigned char * from c++ to c#

So I have a function in unmanaged c++ that gets called when some text happens to have "arrived": #using <MyParser.dll> ... void dump_body(const unsigned char *Body, int BodyLen) { // Need to pass the body to DumpBody, but as what type? ... MyParser::Parser::DumpBody(???); } DumpBody is a static function defined in a C# DLL t...

I'd like to preview a Word document on form.

Update2: For now, I'm considering saving a temporary copy of the document in html format to display it, but this kills my idea to show the user's real time affect on the document. It's just bad practice to re-save at every character input and reload the browser. So, I suppose this may just be impractical for now. I'll keep my ear to ...

Creating and Saving an Excel File

I have the following code that creates a new Excel file in my C# code behind. When I attempt to save the file I would like the user to select the location of the save. In Method #1, I can save the file my using the workbook SaveCopyAs without prompting the user for a location. This saves one file to the C:\Temp directory. Method #2 wi...

Interoperability when returning derived class by base class in WCF

I have some simple code: [DataContract] [KnownType(typeof(SpecialEvent))] public class Event { //data } [DataContract] public class SpecialEvent : Event { //data } [ServiceContract] public interface IService { [OperationContract] List<Event> GetEvents(); } [Service...

Excel manipulation from C# - Set ActiveCell?

I'm currently trying to move some VB6 macros into a C# app and I'm having trouble setting the active cell using C#. In VB6 its simply: ActiveSheet.Range("L1").Select Does anyone know what the C# equivalent is? Cheers in advance. ...

Access COM object through a windows process handle.

I'm currently automating an application at work using COM, and have an issue where anyone using my application has a problem if the original application is already open when my application runs. I know how to locate the process if it's open, but instead of having to worry about closing it, or working around it, etc., I want to try to use...

How to use interop for reading word document and get page number?

Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); object nullobj = System.Reflection.Missing.Value; object file = openFileDialog1.FileName; Microsoft.Office.Interop.Word.Document doc = app.Documents.Open( ref file, ref nullobj, ref ...

.NET COM Interop on Windows 7 64Bit gives me a headache

Hey guys, .NET COM interop so far always has been working quite nicely. Since I upgraded to Windows 7 I don't get my .NET COM objects to work anymore. My COM object is as easy as: namespace Crap { [ComVisible(true)] [Guid("2134685b-6e22-49ef-a046-74e187ed0d21")] [ClassInterface(ClassInterfaceType.None)] public class M...

What are the best practices in language interoperability?

In a system which requires use of multiple languages, what are the best practices to ensure a loosely-coupled architecture when code is calling another language's code? ...

COM interop, Office 2010 x64 and Visual Studio 2010.

Hi, I just installed Office 2010 x64 on my Windows 7 x64 laptop. It already had Visual Studio 2010 on it. Now I try to add Microsoft.Office.Interop.Excel or something to the project, but it just can't find the project. When I try to open a project from the website of Microsoft (a sample of Office development) Visual Studio says that ...

Accessing a namespace containing .base in its name from F#

As the title says, I'm trying to use a class declared in a namespace which contains "base" in its name. Think of a situation like the following: open Foo.base.Bar In C# I'd just use @ before base but F# seems to ignore that and to think that @ is the infix operator used for list concatenation. Since the namespace belongs to a third-par...

Importing a C DLL's functions into a C++ program

I have a 3rd party library that's written in C. It exports all of its functions to a DLL. I have the .h file, and I'm trying to load the DLL from my C++ program. The first thing I tried was surrounding the parts where I #include the 3rd party lib in #ifdef __cplusplus extern "C" { #endif and, at the end #ifdef __cplusplus } // ext...

excel dcom error. excel file not getting created on server side

i am getting this error when i try to create and excel file on my server through asp.net vb.net code. System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space. • To make more memory available, close workbooks or pr...