interop

Getting Object Functionallity out of C++ code in C#

I have have a function in wrote in C++ that calls some functions in a old lib. This function creates some memory makes the calls and destroys the memory. To optimize this I would create an object that would keep the memory allocated until the object was destroyed. However I'm going to be calling this function from C# and don't believe I ...

DllImport - PreserverSig and SetLastError attributes

Hi On the MSDN I've found the following description for the two attributes: PreserveSig Set the PreserveSig field to true to directly translate unmanaged signatures with HRESULT or retval values; set it to false to automatically convert HRESULT or retval values to exceptions. By default, the PreserveSig field is true. SetLastError En...

Track DLL dependencies for wrapping a native C++ DLL to .NET

I have a C++ DLL (no code) that I want to expose to .NET applications. After pondering all the options I have/know of/could find (COM, P/Invoke, SWIG, etc.), I'm writing a .NET Class Library (in C++/CLI). Now the resulting DLL (class library) requires the original DLL and its dependencies, too. My problem lies in automagically keeping t...

COM Interface question - .NET

Hi Recently I was reading about interop marshalling but I still don't understand one thing. To make .NET assembly visible to COM I need to use tlbexp tool and/or regasm tool. To make COM visible to .NET assebly I have to use tlbimp tool - all that is clear for me. Apart from that, I've seen on the internet a lot of code dealing with C...

Wrapping up a C++ API in Java or .NET

Has anyone successfully "wrapped up" a C++ API in Java or .NET? I have an application that provides a C++ API for writing plug-ins. What I'd like to do is access that API from .NET or Java. Would I need to use COM, or are there simpler/better alternatives? ...

.NET get selected text position cordinates from another window

Hello, I have .NET WPF application, that sits in background, and responds to user selecting text for example in Microsoft Word. After user selects text I need to draw window next to selected text. My question is: How it is possible to get selected text coordinates in currently active application? As I understand it has to do with Int...

Marshal.ReleaseComObject ?

I'm playing around with these two native win32 functions: [DllImport( "oleacc.dll" )] public static extern int AccessibleObjectFromWindow( IntPtr hwnd, int dwObjectID, ref Guid refID, ref Accessibility.IAccessible ppvObject ); [DllImport( "oleacc.dll" )] public static extern uint AccessibleChildren( Accessibility.IAcce...

How can I get tlbimp to not automatically generate assemblies for referenced types?

I want to create an interop assembly from a type library using the tlbimp.exe tool that is included in the .NET SDK. My problem is that the source type library is referencing a type in another library that I do not have available. How can I get tlbimp to not automatically generate assemblies for referenced types? I get the following e...

Excel Sheet Project References

Hi All, I am programatically opening excel workbooks under a folder tree to check for some project references using the following code - workbook = app.Workbooks.Open(fileName,false,true,Missing,Missing,.....); foreach(Reference r in workbook.VBProject.References) { //check for a specific reference here } This works fine but m...

Calling C# code from C++

I need to be able to invoke arbitrary C# functions from C++. http://www.infoq.com/articles/in-process-java-net-integration suggests using ICLRRuntimeHost::ExecuteInDefaultAppDomain() but this only allows me to invoke methods having this format: int method(string arg) What is the best way to invoke arbitrary C# functions? ...

Copying multiple worksheets simultaneously to preserve chart references

I've created a two-worksheet template in Excel - the first sheet is for pretty charts, and the other sheet is for the data that drives those charts. I've written a vb.net 2005 app that can dump in all my data on the second worksheet, and the chart worksheet updates perfectly. I would like to do this report several times over in the sam...

p/invoke C function that returns pointer to a struct

How do I declare in C# a C function that returns a pointer to a structure? I believe following is one way to do that, followed by Marshal.PtrToStructure to get actual structure value. // C-function SimpleStruct * Function(void); // C# import [DllImport("MyDll.dll")] public static extern IntPtr Function(); Am I correct about that? A...

WCF Interop with Axis2 using WS-Trust

We are trying to get WCF and Java talking to each other using SAML tokens issued from an STS. Despite the fact that both sides are compliant with the standards, WS-Security, WS-Trust, WS-Policy, etc., they don't seem to talk to each other and one or the other will throw cryptic exceptions or ignore security headers. We are using .NET 3....

C# and Excel Interop issue, Saving the excel file not smooth

Hi, I could Open and Write to the excel file, but when I try to save the file by passing a path to it, the save operation prompts with the Save dialog. I was expecting it to quitely Save the file at the specified path The code is as below: excelApp.Save(exportToDirectory); excelApp.Quit(); where, exportToDirectory is: "C:\files\stri...

Formatting Issues with Excel Interop using C#

I have a C# application that uses an existing Excel spreadsheet as a template and fills in data. In the template there is a blank row that has some style formatting such as font/border and data formatting such as currency and percentages. When filling in the data from the application I copy this row n times and fill in the data. The s...

C# using Excel Interop Updating Formulas

I have a C# application that builds Excel files from an existing template. On the template I want to have my row totals/averages in place and to update to however many rows are inserted by the application (Between the header and footer rows). This should be simple but I am drawing a blank in trying to remember how to do such a thing. ...

How to use .Net assembly from Win32 without registration?

I'd like to dynamically load and use a .Net assembly created in C# from a Delphi Win32 application. My classes and interfaces are marked as ComVisible, but I would like to avoid registering the assembly. Is this possible? P.S. I found here link text another good discussion on the topic, but it is more around hosting the CLR. Which begs ...

How to keep Excel interop from stealing focus while inserting images

I'm using the Excel COM interop to insert images (specifically EPS) into a spreadsheet. The images are inserted fine, but Excel ignores all the visible/background settings and steals the focus the display a dialog box saying something like "importing image". The dialog box only stays a fraction of a section, but it makes the screen fli...

The correct way to call unmanaged code from partially trusted code

What is the correct way to call unmanaged code such as a COM API through .Net interop from a code that is being executed in a partially trusted environment? While developing an ASP.Net WebPart for Microsoft SharePoint I had to communicate with another system through its COM API. I solved this issue temporarily by changing SharePoint's p...

Sending attachments from Axis webservice to .NET client?

Trying to provide a web service capable of sending files to a client on request, I run into the following problem: On the server side, the service is written in Java, using Axis 1 v1.4.1 (I know, it's obsolete, but it's a legacy application which I'm supposed to extend, and the effort involved in migrating to something more up-to-date, ...