Click here to Skip to main content
15,881,559 members
Everything / Interop

Interop

interop

Great Reads

by Leif Simon Goodwin
How to pass strings between managed and unmanaged code
by Christ Akkermans
An introduction to the strange world of mixed language programming with FORTRAN and C# .NET code
by Debabrata_Das
This article will talk about how a WCF service can be consumed by a Java client application.
by koolprasad2003
This article explain you How to protect word document using C# and Word automation

Latest Articles

by ToughDev
How to convert OFT to .NET Windows Form in VS
by William Damert
Console .NET application using Microsoft.Office.Interop.Word for keyword search
by Lee P Richardson
Which SPA technology should you use: Blazor WebAssembly or something more mature like Angular, and why?

All Articles

Sort by Score

Interop 

7 Jul 2017 by Leif Simon Goodwin
How to pass strings between managed and unmanaged code
16 May 2016 by Christ Akkermans
An introduction to the strange world of mixed language programming with FORTRAN and C# .NET code
23 May 2014 by Debabrata_Das
This article will talk about how a WCF service can be consumed by a Java client application.
24 Nov 2015 by koolprasad2003
This article explain you How to protect word document using C# and Word automation
24 Dec 2013 by Reiss
This is an alternative for "How to Check Whether Word is Installed in the System or Not"
12 Apr 2013 by NightWizzard
...for example a WYSIWYG HTML editor to edit or display emails...
20 Apr 2015 by Mario Z
Hi, try this:var application = new Application();var document = application.Documents.Open(FileName: @"C:\Sample In.docx");var tocRange = document.Range(0, 0);var toc = document.TablesOfContents.Add( Range: tocRange, UseHeadingStyles: true);toc.Update();var...
8 Nov 2015 by koolprasad2003
This article help you to create word table using OpenXML without interop object
26 Aug 2011 by Brian C Hart
C# code to format a certain range of Excel cells using the Format As Table button -- but from C# interop code
11 May 2012 by OriginalGriff
HRESULT is a Int32 value - so use that in your DLLImport declaration, and check the actual int returned against the range of valid values. There is a list of common ones here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378137(v=vs.85).aspx[^]and a more extensive list here:...
13 Nov 2012 by Lucas Martins de Souza
Hello there folks! :)After non-stopping researches I just made an simple example work out. And now I think I can expand that to my hole project!The way to go is by using OPEN WATCOM FORTRAN ( whitch is free, dowload it here: http://www.openwatcom.org/index.php/Main_Page[^] and I used...
3 Dec 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
After the tip on Excel and Word, here we will explore the trick to verify whether Powerpoint is installed in the client's system or not by C#.
13 Sep 2014 by koolprasad2003
This tip gives you an idea about how to create Word table using C# (Word automation)
11 May 2012 by Sergey Alexandrovich Kryukov
The question has nothing to do with HRESULT. You would need to use it the same ways as in COM. The only problem is using unmanaged DLL in your .NET assembly.There are two ways to do it.First one is P/Invoke. If you need learn P/Invoke, please...
9 Aug 2020 by Lee P Richardson
Which SPA technology should you use: Blazor WebAssembly or something more mature like Angular, and why?
2 Sep 2010 by Erich Ledesma
I've barely used labview and never used interop with it. So excuse me if I'm not a good help.There are a couple of problems involved here.1- By using out double[,] I'm guessing you want to get a memory block, reserved in the labview VI. This is a problem by it self. Memory blocks cannot...
26 Mar 2013 by Sergey Alexandrovich Kryukov
There are at least three approaches:Don't writeusing Systems.Windows.Window;andusing Microsoft.Office.Interop.Excel;in the same file. Skip on one of those lines, or both. When a namespace is used, use fully-qualified names, such asMicrosoft.Office.Interop.Excel.Window myWindow =...
20 Jun 2014 by Pavel Sinkevich
Combine several API for MS Project Server to achieve complicated goals
22 Apr 2016 by Richard Deeming
Oh boy. Where to start?First of all, the FileName property of the PostedFile object is just the name of the file on the client. Your code is executing on the server. You can't just open that path from the server, because it doesn't exist.If you want to do something with the file on the...
10 May 2016 by F-ES Sitecore
Let's say you can hide the close button, I can still ctrl+f4, chose Exit from the file menu, use task manager, and probably 100 other ways to close the app.You can't launch apps that the clients can't close, it would be an incredibly irritating and spammy thing to do.
21 Aug 2017 by Graeme_Grant
Have a read of these: * c# - Multiple users writing concurrently to shared Excel file using OpenXML - Stack Overflow[^] * One Excel file, multiple editing users, live updates - Super User[^] * How to Make Excel Allow Multiple Users | Chron.com[^]
5 Aug 2010 by Christian Graus
If you don't have Excel installed, what do you hope to interop with ? You must have it installed, or it plain would not work. The code you write simply controls Excel via COM, it is not Office, or Excel.
19 Dec 2010 by Brian C Hart
You know that little "Merge and Center" button in Microsoft Excel? Here's how to 'click' it in C# with Excel Interop (and this carries over to VB etc, too).
23 Feb 2011 by Olivier Levrey
Assigning a char pointer like you did doesn't copy a string. And you don't need unsafe code to convert strings: static void Main(string[] args) { IntPtr ptr = Marshal.AllocHGlobal(255); Error(ptr); string msg =...
25 Mar 2011 by Sergey Alexandrovich Kryukov
Oh, no, this is impossible. You can only P/Invoke a DLL, more exactly, using PE (Portable Executable) file you can link the functions exported.I think you simply need to use WINMM.DLL instead.If the LIB file is not link library for any DLL or you don't know what DLL you should use, this...
17 Aug 2011 by #realJSOP
Your best bet is to google variations of "c# interop services", and look for stuff that resembles what you unmanaged DLL does as far as return types and parameter types are concerned. You didn't mention if it was a standrad C++ dll or a MFC DLL (or what *kind* of MFC dll) it is, so you should...
18 Oct 2011 by Sergey Alexandrovich Kryukov
First, "Managed C++" was superseded by C++/CLI which you tag, so this is hardly an option. Everything else really depends on details of your requirements and even of the level you are familiar with the technologies. In this case, it's not possible to justify any advice of the type "use just...
17 May 2012 by Member 8147724
you can try with this one [DllImport("CRT450U.dll")]public static extern Int32 CommOpen();[DllImport("CRT450U.dll")]public static extern Int32 CommClose(Int32 hcom);[DllImport("CRT450U.dll")]public static extern Int32 GetDeviceCapabilities(Int32 hcom, ref Int32...
9 Jul 2012 by Jackie00100
okay fixed this my self after finding the right imports...EDIT:Source code:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using...
2 Dec 2012 by CHill60
Firstly your comment "which read first worksheet (by default)" isn't quite accurate - it's simply that the first sheet was active the last time you saved the spreadsheet ... if you had left the 2nd sheet visible before saving and closing the spreadsheet then the second sheet would have been read...
19 Jun 2013 by Sergey Alexandrovich Kryukov
The scenario with the thread should be explained in more detail: you have to use such an non-trivial tool as System.Threading.Thread.Abort:http://msdn.microsoft.com/en-us/library/system.threading.thread.abort.aspx[^].In contrast to some common believe, it does not terminate thread. It...
29 Oct 2014 by Christian Sack
So here is the full working code: public static PingReply Send(IPAddress srcAddress, IPAddress destAddress, int timeout = 5000, byte[] buffer = null, PingOptions po = null) { if (destAddress == null || destAddress.AddressFamily != AddressFamily.InterNetwork ||...
30 Apr 2016 by Christ Akkermans
Part II of the FORTRAN Interoperability with .NET series where we introduce the ISO C Binding which greatly simplifies interoperability.
21 Jun 2017 by kozmikadam
Here is the solution. First of all i get column count with a for loop. I count every column in this loop. Already have this loop also. And then convert the count of column to alphabetical version with this code. private string GetExcelColumnName(int columnNumber) { int dividend =...
17 Aug 2017 by Dennis Wu CA
A demo that generates a simple Excel spreadsheet with subscripts and superscripts
15 Feb 2021 by amirea
I need to keep references in unmanaged code to objects on managed side, like handles. There are going to be approx. 10,000,000 objects. I'm not familiar with interop, initially I thought it was as simple as declaring ref SomeClass on C# side...
15 Feb 2021 by KarstenK
You shouldnt do that this way, but really think hard about using so many objects at once. If you really need that heavy load than you better code the program in one language to get best performance with that many objects. Else you can use the...
26 Jul 2010 by RebornDeveloper
HiI have restarted developing in C# after quite some time. It's like i have taken a long break.But anyway to get to the point, I have a situation where I need to upload the contents of an Excel file into SQL Server tables through a C# application that i am designing.What would be the...
5 Aug 2010 by Corayzon
Update.I am using OLE connection to retrieve data.Results.QueryData = new DataTable(); using (OleDbConnection OleConnection = new OleDbConnection(QueryConfiguration.OleConnectionString)) { OleConnection.Open(); using...
2 Sep 2010 by Member 2847006
I have created interop dll for labview VI's.I am using interop dll in .NET environment.The method signature is: public static void ReconstructRawData(byte COMPort, double[] FlowValuesFullScaleFlow, double[] TemperaturesC, ErrorCluster errorin, byte Gastype, bool ValueFormatrealunitsFalse,...
6 Sep 2010 by BaptX
Hi there,I have a question about Interop between C# and C/C++. That's the situation :- I need to develop a C# dll (MS VS2010)- A c++ software (C++ Builder IDE) must call this dll in order to do some stuffThis is the code of the calling method (C++) :// Loading DLLif (enCr ==...
6 Sep 2010 by Ketan D Kulkarni
If you want take C# dll in to native VC++ (VC 6.0 ) runtime then you may register C# dll as COM class using regasm.exe and call functions ...and If you are building your projects in vc++ ( VC++ studio 2008 ) with /clr option then you can just add reference of C# dll in C++ software project...
1 Nov 2010 by Henry Minute
The last answer in this[^] thread seems to have a solution although perhaps if you edit your question to explain exactly what it is you are trying to do, and why, someone might suggest a better method.
23 Mar 2011 by Wendelius
There are several tools available to do this for you. Writing the converter yourself more likely takes more time that rewrite the application itself. Google for example "convert vb6 to vb.net" and you'll get results like: -...
23 Mar 2011 by Dalek Dave
There are vb6 to vb.net converters.They cost money and are not entirely reliable.For several years now Microsoft have been telling people "We no longer support VB6", so even their converter is no longer available.You will have to bite the bullet I'm afraid, and start from scratch on a...
23 Mar 2011 by AspDotNetDev
You can use the Interop Forms Toolkit to use VB.Net controls from your existing VB6 application. You can also use VB6 controls in your VB.Net application. It may also be of use to you to call a VB.Net DLL from VB6. Again, you can do the reverse and call VB6 code from VB.Net.Those links...
1 Apr 2011 by poloyzhang
using assembly referenceplease send a specific Code in you problem.
2 Apr 2011 by RaviRanjanKr
Take a look there-CPArticle[^] to learn how to export Grdiview data to Excel.
2 Jun 2011 by R. Hoffmann
Hi guys,Apologies in advance for the long post!I have to change the colours of the slices in a pie chart to automatic, using COM automation. In other words, I need to programmatically achieve the same as if I had right-clicked a pie chart in Excel (2007), selected "Format Data...
2 Jun 2011 by Maciej Los
In your example, you need to ClearFormats for ChartArea and then set ChartType and other options:In Excel VBA:Option ExplicitSub SetAutoSlices()Dim chrt As Chart, chrtA As ChartArea, chrtG As ChartGroupDim wsh As WorksheetOn Error GoTo Err_SetAutoSlicesSet wsh =...
2 Jun 2011 by Ruard
This should work:dataSeries.Interior.ColorIndex = XlColorIndex.xlColorIndexAutomatic
20 Jul 2011 by Albert Holguin
Your interface class implementation should probably be contained within your namespace.
31 Jul 2011 by Shameel
Use the fixed[^] statement
28 Aug 2011 by Suresh Suthar
I think there is some problem in getting range of excel cells.You can find a VB.Net article on this here. Go to third section Object Pasting Method, I have used Range to populate the Excel Sheet.Or these link might help...
28 Aug 2011 by Abhinav S
Fairly useful link[^], should definitely help you out.
18 Sep 2011 by skoooons
I've added an reference to assembly "Interop.QuotesPlus.dll" in my solution, so a namespace QuotesPlus became visible with several classes inside. It seams to be machine generated IDispatch wrapper classes created with ClassWizard.After a first use of any of that classes' method, it locks...
18 Oct 2011 by Simon Bang Terkildsen
WCFSeems lake a hassle, to me, to write a host implementation of WCF in unmanaged C++.SocketsThis is an option, however I've never really used them so I don't know how feasible it is. That said if you need to communicate with something like Java where you can't use Named Pipes.Named...
18 Oct 2011 by Espen Harlinn
If you want to get the job done in a hurry - use COM Interop[^].Net has great support for COM, and COM enabling an MFC app is usually a straight forward process.Best regardsEspen Harlinn
12 Jan 2012 by Maciej Los
Use this: iCountOfApples = ExcApp.WorksheetFunction.CountIf(ObjectRange,StringToFind)whereiCountOfApples - id the integer variableExcApp - is the object variable, type of: the instance of MS Excel ApplicationObjectRange - is the object variable, type of: RangeStringToFind - is the...
17 Jan 2012 by hulzi
after 3 days debugin and afert poste my problem i have the solution :-)m_ExcelApp.AddIns(mscorre.dll) says, that the AddIn (Automation AddIn) is installed.But this is wrong.You have to set the property to false.Then Register the .dll again and set the property to true.foreach...
7 Mar 2012 by Lakamraju Raghuram
Hope this will helphttp://msdn.microsoft.com/en-us/library/367eeye0(v=VS.100).aspx[^]
17 May 2012 by krmed
Admittedly, I haven't thoroughly read all the previous responses/comments, but here's something I see.The api says the function prototype is:int APIENTRY CRT450_ReadCard (HANDLE ComHandle, BYTE _ReadOption, BYTE _WaitTime, bool *_IsOutofTime, BYTE *_mode,BYTE _CardData[],int...
25 Jul 2012 by Christian Graus
If you have a vanilla dll you're calling, then you can use pinvoke if you get the code right. If you're writing the dll, you're better off using COM to get it to work with VB6, assuming you have no choice in that question.
22 Oct 2012 by dashingly
I had to check if value was null, but it only worked in the certain way: if (rng.Value2 != null){}
1 Nov 2012 by Maciej Los
First of all, read these articles:http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.validation%28v=office.11%29.aspx[^]http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.validation_properties%28v=office.11%29.aspx[^]If you would like to use...
14 Feb 2018 by Haseeb4328
Hello, I want to read multiple worksheets which exist within same excel file. Following is my simple code which read first worksheet (by default), i want to read second as well. There will be change in argument but i don't know. Your help is highly...
26 Mar 2013 by Marco Bertschi
Hi,there is an article series (called Espresso- Java & .NET Native Interoperability)[^] on CodeProject.You might want to read it, IMO it can give you valuable inputs.cheers,Marco Bertschi
17 Apr 2013 by Member 9994487
There is a library (MSG.Net) available that can help you outhttp://www.independentsoft.de/msg/tutorial/readmessage.html
14 May 2013 by CHill60
To improve performance you need to minimise the use of the Excel COM interface.I would suggest converting your list of objects to a datatable first and then exporting that to excel ...Here is a generic way to convert a list to a datatable Converting a List to Datatable[^]and here's how...
14 May 2013 by Maciej Los
If you fetching data from database, the fastest way to export data is to use CopyFromRange()[^] method for MS Excel range.More about: How to transfer data to an Excel workbook by using Visual C# 2005 or Visual C# .NET[^]
28 May 2013 by Sergey Alexandrovich Kryukov
This is a very unreliable technique. If you wan to simulate input, you should better use really low-level method SendInput:http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].This is how to do it in .NET:...
30 May 2013 by Iain Clarke, Warrior Programmer
This is a bit of an interop question, so I thought I'd ask those wiser than me (so, that's most of you...)I have a bit of C# code, wrapped up in COM:namespace Blah{ public interface Blether {... [DispId(19)] int IainTest(ref byte[] Hello); }}I am setting up a...
31 May 2013 by KarstenK
if that worksvtParam [n].vt = VT_UI1 | VT_ARRAY;vtParam [n].parray = pMySafeArrayOfBytes;dont use the VT_BYREF flag. This will transport a pointer, which is invalid/inaccessable in another process.Consider marshalling as a "package service" which want to deliver packets od data not...
19 Jun 2013 by Ron Beyer
The only way I know how to do it is to run the function on a separate thread, and then terminate the thread when you are done.Look up threading and interop on google. .NET can generate interop assemblies for you in most cases.Interop In .NET[^]
26 Jun 2013 by naveu2007
Hi all resolved my issue :):) thanks for the support..Just replaced the code as belowforeach (Word.ContentControl contentControl in document.ContentControls){ contentControl.Range.Text="Trial"; contentControl.Delete(false);}
9 Feb 2014 by Abhinav S
Did you try Range.Find - http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.find.ASPX[^].Also try - Programmatically Search for Text in Worksheet Ranges[^]
13 Feb 2014 by hari111r
I am trying to convert word document to html in my asp.net applicaiton. it working fine in debug mode after i publish an hosted it is not working and i am getting the error "This command is not available because no document is open."Below is the code i am usingif...
13 Feb 2014 by Sergey Alexandrovich Kryukov
Microsoft does not recommend to use Office Interop in server settings:http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],http://support.microsoft.com/kb/257757/en-us[^].I would advise to use Open XML SDK...
13 May 2014 by Maciej Los
Try Marshal.GetActiveObject[^] method as is described here: Launching Office Apps Programmatically[^]
9 Sep 2014 by johannesnestler
Hi John,Just a quick message - no solution I fear... Just want to tell you what I found out (or not)...The documentation for EnumerateChildWindow states:Enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an...
9 Sep 2014 by George Jonsson
I changed the logic inpublic bool EnumerateChildWindow(IntPtr hwnd, IntPtr lParam){ bool result = false ; GCHandle gch = GCHandle.FromIntPtr(lParam); List list = gch.Target as List; if (list != null) { list.Add(hwnd); result =...
20 Apr 2015 by eswarpabolu
I have an unmanaged DLL that exports only a C style factory method that returns a new instance of a class (simplified here to look simple).hello.h#if defined(HWLIBRARY_EXPORT) // inside DLL# define HWAPI __declspec(dllexport)#else // outside DLL# define HWAPI ...
15 May 2015 by Richard Deeming
There are several free and open-source components which will let you do this without needing to have Excel installed. For example:http://epplus.codeplex.com/[^]http://closedxml.codeplex.com/[^]https://github.com/tonyqus/npoi[^]The OpenXML SDK[^];
18 May 2015 by Sergey Alexandrovich Kryukov
Sure. The better alternative could be not using Excel at all. Instead, you can use Microsoft Open XML SDK. Please see my past answers:Microsot office Interop[^],How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].See also this CodeProject...
10 Aug 2015 by Dave Kreskowiak
Not possible. Code running on a web server can NOT launch an executable on a client machine, let alone "monitor" it for events.
12 Sep 2015 by Maciej Los
This piece of code causes error:CType(DataGridView1.Rows(i).Cells(1).Value, Microsoft.Office.Interop.Excel.Worksheet)I'd suggest to get dataGridView cell value into string variable:string sheetname = DataGridView1.Rows(i).Cells(1).Value;then to create object variable (of...
23 Sep 2015 by Richard Deeming
You should read the following Microsoft knowledgebase article:Considerations for server-side Automation of Office[^]Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component...
7 Nov 2015 by andrewj86
Started experiencing the same error out of the blue yesterday in Outlook VBA. Finally found a workaround.Changed this:Set teamBox = objNS.CreateRecipient("Our.Shared.Mailbox@domain.tld")Set olTeamBoxItems = objNS.GetSharedDefaultFolder(teamBox, olFolderInbox).ItemsTo this:Set...
4 Feb 2016 by Dave Kreskowiak
I seriously doubt you'll ever find one that covers all those topics in one plan.You'll stuff that covers sections of those topics, for example, Introduction to the .NET Framework, Introduction to C#, Unit Testing for Beginners, but you'll never anything that covers all of this stuff advanced...
17 Mar 2016 by F-ES Sitecore
Using Excel interop is a bad idea as it isn't supported and it's going to fail and give you all sorts of errors. Also no doubt you're still coding this on your local development machine and haven't tried to deploy it yet so have no idea the issues you face.Instead use a library that is...
12 Jan 2017 by Maciej Los
You need to use loop, i.e.:for(int i=1;i
16 Apr 2017 by Dave Kreskowiak
You cannot use Office Interop in an ASP.NET application. Why? Multiple requests at the same time are not supported. In other words, Office apps don't support reentrancy. You can read more about it here[^]
22 Jun 2017 by Patrice T
I wonder why you are using those coordinates which is a GUI thing for users ? Why don't you tell your program to use directly the column number ? Excel.Range araAt = raporWrkS.cells(columnNumber,1); araAt.EntireColumn.Insert(Excel.XlInsertShiftDirection.xlShiftToRight,...
30 May 2018 by Gerry Schmitz
Your app openened a SECOND copy of the "active document" ... there is no meaningful cursor info.
12 Aug 2018 by Richard MacCutchan
The GetWindowText function (Windows)[^] requires the second parameter to be the address of a memory buffer. You are passing s StringBuilder reference.
5 Feb 2020 by Maciej Los
As you mentioned, you have to use Find method. See: Find and replace text in documents programmatically - Visual Studio | Microsoft Docs[^] How to: Programmatically loop through found items in documents - Visual Studio | Microsoft Docs[^] How to: Programmatically restore selections after...
6 Feb 2020 by Fred Andres
Thanks for your help Maciej. With your information I was able to come up with the following solution which is lightening fast: public void find_and_replace_text(string curr_text, string new_text) { Word.Find findObject; var missing = Type.Missing; ...
23 Mar 2020 by OriginalGriff
Quote: Page means sheet I dont know which line exactly ,because in a sheet there will be 1000 rows to debug and exception behavior is not consistent. If you are going to learn to develop code, you need to know the terminology and use it...
30 Nov 2021 by Richard Deeming
Load the data into a single DataSet: private static DataTable LoadTable(string connectionString, string query, string tableName) { using (var connection = new OdbcConnection(connectionString)) using (var command = new OdbcCommand(query,...
4 Aug 2022 by Richard MacCutchan
You just need a set of data (an array or collection) that you want to put in the cells. So replace (cell.RowIndex - 3 + cell.ColumnIndex).ToString() with each item of your data.