interop

How can I pass a pointer to an integer in C#

I have a C API with the signature: int GetBuffer(char* buffer, int* maxSize) In C, I will call it this way: char buffer[4096]; int maxSize = 4096; GetBuffer(buffer, &maxSize); maxSize is set to the buffer size, and set with the actual size filled. I need to call it from C#. How do I do that under "safe mode"? Thanks ...

Marshalling .NET generic types

Here is a C# program that tries Marshal.SizeOf on a few different types: using System; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] class AClass { } [StructLayout(LayoutKind.Sequential)] struct AStruct { } [StructLayout(LayoutKind.Sequential)] class B { AClass value; } [StructLayout(LayoutKind.Sequent...

How to disable conversion message when opening Office 2007 doc using Office 2003?

I am working on a C# application which opens Excel workbooks using Interop. It works fine except for one annoyance: when opening an Excel 2007 document on a machine using Excel 2003, a small message pops up saying "File conversion in progress". Does anyone know of a way to prevent that message from appearing at all? ...

Using SetWindowTheme() on controls in WindowsFormsHost in WPF?

I have an application I'm developing which closely mirrors Windows 7's Device Stage. In Device Stage, beneath the main banner there is a ListView containing actions embodied as ListViewItems. In my WPF application, I used WindowsFormsHost to host a WinForms ListView so that I could use SetWindowTheme() on it and apply Windows Vista/7 st...

Java/C# Kerberos inter-op possible?

Hi there... I have implemented a Kerberos server/client using sockets in Java, where the client sends his service-TGT to the server, and the server knows the client is authentic. My main concern is the snooping 'man-in-the-middle' attack. Someone could capture the TGT, and pretend to be the client. In a pure Java implementation, ...

Objective-C and C interoperability

We're going to have to write a C library and this library has to be accessible from Objective-C. Now I don't know anything about Objective-C so I wonder how simple Objective-C <-> C interoperability is. Is that as simple as including the C header in the Objective-C code and linking to the library? Is there anything special I'm supposed t...

Position cursor at start/end of Word document

We are manipulating our Word 2007 documents from .Net using Word Interop. Mostly doing stuff with fields as in: For Each f In d.Fields f.Select() //do stuff with fields here Next This leaves the last field in the document selected. So, for the sake of neatness we would like to positi...

What is the AppDomainSetup.SandboxInterop Property for?

I am using reading the documentation for app domains in .net 3.5 and came across SandboxInterop. The docs says Gets or sets a value that indicates whether interface caching is disabled for interop calls in the application domain, so that a QueryInterface is performed on each call. But why would I ever wish to disable the caching of Qu...

Send Authenticated User To WCF Application

I have 2 applications; one is a ASP.NET 3.5 Ajax Application (Client) and the other is a WCF Web Application (BackEnd). The applications are deployed in a separate Windows Server 2008 over IIS 7. The backend application has the net.tcp and http bindings enabled; some services are exposed under the netTcpBinding and other services are e...

Is there a more painless way to call Win32 from C#?

Every few months I find myself needing to call Win32 from C#. Though I've done it a dozen times, I've usually forgotten the exact machinations, so I poke around the web or old code and figure out what DllImport statements I need, etc. Am I alone? Is there a sanctioned "Win32" class that has the requisite declarations for the entire Win...

How to replace FileName in SaveFileDialog.FileOk event handler

I'd like to change the file name of the SaveFileDialog in the event handler attached to the FileOk event, in order to replace the file name typed in by the user with another file name in some cases, while keeping the dialog open: var dialog = new SaveFileDialog(); ... dialog.FileOk += delegate (object sender, CancelEventArgs e) ...

Calling Web Service with WSE 3.0 from COM+

I have to update a COM+ application to call a web service that uses WSE 3.0. What is the best way to call the web service from the COM+ client? My current plan is to create an Interop assembly like this: COM+ Client <--> Interop Assembly <--> WSE 3.0 Web Service Wondering if anyone has some guidance on best practices for this type of s...

how to set bold and italics when using the outlook interop from C#

I have the following C# code to launch an outlook window. The one think i want to add it to have certain part of the text bold and italics. how would i do that through this API? Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook...

How to return an array of C# strings (string[]) to unmanaged C++ code?

How to return an array of C# strings (string[]) to unmanaged C++ code, and then use it from C++? // Is it correct ??? [ComVisible(true)] public string[] Foo() { return new string[] {"A", "B", "C"}; } C++ code ?? ...

c# interop marshalling and disposing

I have a DLL, which is designed in C++, included in a C# project and I have strange AccessViolationExceptions happening unrationally. I suspect that my garbage isn't collected correctly. I have an unmanaged method apiGetSettings (from the DLL) which should copy data to a Settings object (actually a struct in the original code, but .NET I...

PInvoke - reading the value of a string field - "Attempted to read or write protected memory"

I'm having trouble accessing the some string fields in a COM interface. Calling the integer fields does not result in an error. When attempting call clientID(), deviceID() or key(), I get the old "Attempted to read or write protected memory" error. Here is the source interface code: (code sourced from here) [scriptable, uuid(fab51c92-9...

C# - EasyHook CoCreateInstance

I'm working the open source library EasyHook. What I'm trying to do, is hook into when a VB6 app calls CoCreateInstance from ole32.dll on a particular CLSID, return my own C# implementation for the object rather than the true COM object. My C# implementation derives from the same interface that tlbimp.exe spits out for the COM object I...

Properly accessing a SafeArray of VT_UNKNOWN with SafeArrayGetElement

We have a COM component who’s implementation and interface definition exist in managed code but is driven by a native component. The managed component is returning a SafeArray back to the native code via the following method declaration. interface IExample { <return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_UNKN...

Need a good book(s) and information about working with unmanaged code and COM with .Net

I have been working with .Net since VS2002 and since then any time that I had to work with COM or unmanaged code has been a pain. I've succeeded doing what was expected but almost always doing a trial-error procedure. I've had enough of this and I want to know what's going on at the back room and understand how those things work. As us...

With which versions of GWT does Seam work?

Hello, I recently tried to combine SEAM and GWT in a project - but failed using GWT 1.7.1 and Seam 2.1.2 CR2 and Seam 2.2.0 GA (if you have any ideas why - here is the post). I was wondering: Do you have any experiences which versions of GWT work with which version of SEAM out of the box? With workarounds? Thx! (PS: For Seam < 2.1.0 an...