interop

C++ Wrapper Native Interop Enterprise Scale

I want to know what is the best approach to wrapping a massive library written in C++ to make it accessible in C#. I have done work with interop before, and I love IJW. But I am not sure of how to implement this approach with a huge library. I am wondering if there is any pattern to use, otherwise I just have to write a wrapper around...

Office Interop Word c#.net : Copying a table at a special location

I'm currently working on tables in a Word template with Interop. In my template I have a table which I want to copy (Copying will make it easier for me to fill in the data rather than inserting rows and column, because the template has a lot of write formatting). The new table should be inserted right under the original table. The best...

How do I properly return a char * from an Unmanaged DLL to C#?

Function signature: char * errMessage(int err); My code: [DllImport("api.dll")] internal static extern char[] errMessage(int err); ... char[] message = errMessage(err); This returns an error: Cannot marshal 'return value': Invalid managed/unmanaged type combination. What am I doing wrong? Thanks for any help. ...

How come replacing char[] with IntPtr or StringBuilder in a DllImport return value causes my program to no longer find the correct entry point?

EDIT: I just realized this is defined as a MACRO, not a function. How the heck would I import a macro from a DLL to C#? (this may have to be a new question). This is related to a question I just asked: How Do I Properly Return A Char From An Unmanaged Dll To C#? Some of the answers suggested I change the function signature to Int...

What's the purpose of COM+ library applications?

When a COM+ application is created the wizard offers to choose between a library and a server application. A server application is activated in a separate process and this can be used to cheaply interop 64-bit consumers with 32-bit in-proc COM components. What's the use of library applications that are activated right in the caller pro...

Are double* and double** blittable types? C#

Hello, I have a question regarding marshalling of C++ arrays to C#. Does the double* automatically convert to double[]? I know double is a blittable type, so double from C++ is the same as double from C#. And what about double**, does it convert to double[,] ? I have the following unmanaged function: int get_values(double** param,in...

Marshaling Delphi 5 OleVariant to C#

I'm trying to use some legacy Delphi 5 DLLs from C# (2.0/3.5). Some of the exported functions are declared as such: function SimpleExport: OleVariant; stdcall; function BiDirectionalExport(X: OleVariant; var Y: OleVariant): OleVariant; stdcall; I wish to set these up as delegates using Marshal.GetDelegateForFunctionPointer, but I'm ha...

AccessViolationException in COM control in .NET app

I'm working for a client that has a VB6 app in the migration process to .NET. Currently they have a .NET shell, but host some old VB6 controls in .NET. There's an error I stumbled upon is logs that happens when they in .NET asynchronously pull some data from the database, and then forward that data to a COM component to display it: The...

Preventing GetType from throwing exceptions on internal types

Is there any way to prevent o.GetType() from throwing an exception when called on an object whose type is internal and resides in another assembly? I am wrapping a COM based API inside a .Net assembly so that it is possible to benefit from more native .Net integration (Collection interfaces, streams, exceptions etc.). The collections t...

Send message to a Windows process (not its main window)

I have an application that on a subsequent start detects if there's a process with the same name already running and, if so, activates the running app's window and then exits. The problem is that the main window could be hidden (only a notification area icon visible), thus leaving me with no window handle. At startup, previous instance...

F#: Dynamically importing a C/C++ DLL

From what I have learned, to use P/Invoke in F#, the function signature has to be declared first using DllImport like this: [<DllImport("kernel32.dll", EntryPoint="CopyFile")>] extern bool copyfile(char[] lpExistingFile, char[] lpNewFile, bool bFailIfExists); That's all good when the DLL name is known at compile time. How do I interf...

How can I convert scala.xml.Elem to something compatible with the javax.xml APIs?

I have a Scala representation of some XML (i.e. a scala.xml.Elem), and I'd like to use it with some of the standard Java XML APIs (specifically SchemaFactory). It looks like converting my Elem to a javax.xml.transform.Source is what I need to do, but I'm not sure. I can see various ways to effectively write out my Elem and read it into...

How to centrally define IComparable on abstract (interface) types in F#

This question is kind of the next level of http://stackoverflow.com/questions/895769/f-set-using-custom-class -- I want to define IComparable for a generic interface. I have an arbitrary set of types which implement a shared metadata exchange interface, ITree. I want to compare across these types, using only the exposed data in ITree. ...

C#/Access Interop DoCmd value combobox

Hi All I've succesfully connected to a Microsoft Access database through the interop/COM.. I need to put some data into a combo box and Requery so I can get the information displayed. // Create app MsAccess.Application app = new MsAccess.Application(); // Open the database app.OpenCurrentDatabase( ...

Marshalling array of structures from C#.

Hey folks, I have a requirement where I need to marshal an array of structures from managed code(c#) to native code(C++). The structure is something like //need to put any attributes here? public struct inner { [MarshalAs(UnmanagedType.U8)] public long l1; [MarshalAs(UnmanagedType.U8)] public long l2; } public struct ...

Accessing protected memory in C# via COM interop

I am making a DLL "Plugin" for a EXE. The EXE calls a function in the DLL with an Object as a parameter, and goes from there. It all works fine and dandy until I split it to a new thread. This error happens Attempted to read or write protected memory. This is often an indication that other memory is corrupt. when executing thi...

How to declare a union in C#?

Dear ladies and sirs. Observe the following sample code: struct DDD { [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 512, ArraySubType = UnmanagedType.I1)] byte[] x; } struct BBB { DDD x; } struct CCC { DDD x; ulong y; ulong z; } [StructLayout(LayoutKind.Explicit)] struct AAA { [FieldOffsetAttribute(0)] BB...

C#: How can I create a header in a table for each new page with Word interop?

I am trying to create a table with a header. I want this header to be repeated for each new page that the table takes. How can I do this in C# with Word 2007 Interop? ...

Is PIA embedding broken in .NET 4.0 beta 2?

A while ago, I wrote some Word interop examples in Visual Studio beta 1, and set the reference to Microsoft.Office.Interop.Word to be embedded (set the "Embed Interop Types" = true in the reference properties). These worked fine, and I haven't run them for a while... until today. Of course, now I'm running under beta 2 of both Visual St...

c# and excel automation - ending the running instance

Hi! I got the same problem. I read the whole thread and tried the examples given. I added these lines to the sample code: xlRange = (Excel.Range)xlWorkSheet.get_Range("B1", "C1"); xlRange.Merge(Type.Missing); xlRange = (Excel.Range)xlWorkSheet.get_Range("H5", "M5"); xlRange.Merge(Type.Missing); xlRange = (Excel.Range)xlWorkSheet.get_...