interop

Calling a native callback from managed .NET code (when loading the managed code using COM)

Hi, I am really confused by the multitude of misinformation about native / managed interop. I have a regular C++ exe which is NOT built using CLR stuff (it is neither Managed C++ nor C++/CLI and never will be). This C++ exe is "in charge", there is no managed wrapper for it. I would like to access some code I have in a C# assembly fro...

Setting System.Drawing.Color through .NET COM Interop

I am trying to use Aspose.Words library through COM Interop. There is one critical problem: I cannot set color. It is supposed to work by assigning to DocumentBuilder.Font.Color, but when I try to do it I get OLE error 0x80131509. My problem is pretty much like this one. update: Code Sample: from win32com.client import Dispatch Doc = ...

Writing a managed wrapper for unmanaged (C++) code - custom types/structs

faacEncConfigurationPtr FAACAPI faacEncGetCurrentConfiguration( faacEncHandle hEncoder); I'm trying to come up with a simple wrapper for this C++ library; I've never done more than very simple p/invoke interop before - like one function call with primitive arguments. So, given the above C++ function, for example, what should I ...

Excel::Shape object getting released automatically after the count reaches 18 in List<T>

I have a Excel addin written in C# 2.0 in which I am experiencing a strange behavior.Please note that this behavior is only seen in Excel 2003 and NOT in Excel 2007 or 2010. Issue: When the user clicks an import command button, a file is read and a number of Shapes are created/added to the worksheet using Worksheet::Shapes::AddPicture(...

MAPI_E_INVALID_ENTRYID when getting contact from Outlook via Redemption

I'd like to retrieve a contact with a known EntryID in a specific folder from outlook/exchange using Redemption. The following code calls GetMessageFromID on an RDOSession object. I only want contacts from the standard Contacts folder, so I use the second argument to limit the search space. RDOFolder folder = Session.GetDefaultFolder(r...

Finalizing a COM object

I'm trying to implement a singleton class, that holds a com object inside it. Class implements IDisposable interface, but when I try to implement a finalization method, I get an exception of access to com object from another thread. This happens because clr uses a different thread when finalizes objects. Is there any way to implem...

How to declare and implement a COM interface on C# that inherits from another COM interface?

I'm trying to understand what is the correct why to implement COM interfaces from C# code. It is straightforward when the interface doesn't inherit from other base interface. Like this one: [ComImport, Guid("2047E320-F2A9-11CE-AE65-08002B2E1262"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IShellFolderViewCB {...

Global hotkey capture in VB.net

I want to have my app which is minimized to capture data selected in another app's window when the hot key is pressed. My app definitely doesn't have the focus. Additionally when the hot key is pressed I want to present a fading popup (Outlook style) so my app never gets focus. At a minimum I want to capture the Window name, Process ID...

Extract a C/C++ header file from a C# class exposed to COM

I'm not sure I've setup everything I've needed to in my C# class to properly, but it does work in COM. I've been looking for an example of a C# class that was successfully used in a C/C++ project, but haven't come across anything. I've tried using the OLE/COM Object View app to open the .tlb file and save as .h, but it gives some errors...

c# interop with ghostscript

I'm trying to access some Ghostscript functions like so: [DllImport(@"C:\Program Files\GPLGS\gsdll32.dll", EntryPoint = "gsapi_revision")] public static extern int Foo(gsapi_revision_t x, int len); public struct gsapi_revision_t { [MarshalAs(UnmanagedType.LPTStr)] string product; [MarshalAs(UnmanagedType.LPTStr)] strin...

how can we avoid allocation done by Marshal::StringToHGlobalAnsi?

my wrapper from managed to unmanaged is handling a lot of data and this function Marshal::StringToHGlobalAnsi would call new for each of them, which is a big hit for me. So my question is : can I allocate a chunk of unmanaged memory and use it to convert the managed data types to unmanaged by hand. ...

c++/cli pass (managed) delegate to unmanaged code

How do I pass a function pointer from managed C++ (C++/CLI) to an unmanaged method? I read a few articles, like this one from MSDN, but it describes two different assemblies, while I want only one. Here is my code: 1) Header (MyInterop.ManagedCppLib.h): #pragma once using namespace System; namespace MyInterop { namespace ManagedCppL...

Millisecond-Accurate Scheduling of Future Events in C++/CLI

I need to create a C++/CLI mixed assembly that can schedule future calls into a native DLL with millisecond accuracy. This will, of course, mean setting a timer (what kind?) for a millisecond or three beforehand, then spinning until the moment and calling the native DLL function. Based on what I've read, I would guess that the callba...

When calling managed code called from unmanaged code, is it possible to inspect the exception object?

Working with COM interop, I can call a managed function from within unmanaged code. But, this only gives me the HRESULT for the exception, in case a managed exception is thrown. Is there anyway to further inspect the exception from the unmanaged code? For example, to look at the message contained in the exception object. Thanks! ...

Is MEF mature enough to bet the company on ?

My company needs to rewrite a large monolithic program, and I would want it written using a plugin type architecture. Currently the best solution appears to be MEF, but as it is a fairly 'new' thing I am warey of betting the future of my company (and my reputation) on it. Does anyone have a feeling on how mature a solution MEF is ? Th...

Why exception occured at LoadTypeLibEx System.ArgumentException: Value does not fall within the expected range?

Hello, I am loading type library in C++/CLI. In C# its loading successfully but it's giving again and again following exception in managed C++/CLI. exception occured at LoadTypeLibEx System.ArgumentException: Value does not fall within the expected range at LoadTypeLib(String strTypeLibName, ITypeLi b typeLib) Here's a PInvoke Signat...

Excel COM Interop - tlbimp vs primary WrapperTool

I'm trying to add the ActiveX Microsoft Excel 11.0 Object library to my .NET project. It works fine on my computer, but when I check in my code, it doesn't work on my coworker's. Fixed it on his and it broke mine. When added, the namespaces are different between our machines. It turns out the difference is that when I add the reference ...

How to check whether given file is in PROPER word file format?

Hi, I am developing one application using C# for processing MSWord files. My application gets hang when I pass invalid .doc file as an input. For example, if I have one foo.pdf file and I pass it to my application after changing its extension (foo.doc). Is it possible to check whether file is valid doc file before trying to open...

How can I compile some parts of C++/CLI code as Native and some part as Managed?

Hello, I am calling LoadTypeLib for loading unmanaged type libraries in C++/CLI. I need to compile some code(some code areas) as managed and some code areas as unmanaged(native) code and form a mixed mode class library as executable. What i need to mention between the lines of code so that whatever the part i need to be compiled as man...

C# exporting e-mails to excel on widndows forms using microsoft.office.interop.excel

I need to export some data to excel in my forms aplication, so i used microsoft.office.interop.excel and everything is ok except one thing. When exporting client's email I would like to make it an mailto: link. excellApp.Cells[row, 16] = "mailto:"+client.Email; doesn't work When I add hiperlink when exporting www field it looks like...