marshalling

VB.NET Trying to modify a generic Invoke method to a generic BeginInvoke method, having unexpected problems

VB.NET 2010, .NET 4 Hello, I have been using a pretty slick generic invoke method for UI updating from background threads. I forget where I copied it from (converted it to VB.NET from C#), but here it is: Public Sub InvokeControl(Of T As Control)(ByVal Control As t, ByVal Action As Action(Of t)) If Control.InvokeRequired Then ...

COM interop and marshaling of a pointer to a pointer to an interface in C#

I'm attempting to use Microsoft's Text Services Framework in a C# app. So far, it's all gone swimmingly, but I've run into something that has me stumped. According to the MSDN docs, the ITfFnReconversion interface publishes this method: HRESULT GetReconversion( [in] ITfRange *pRange, [out] ITfCandidateList **ppCandList ); ...

Platform Invoke, bool, and string

Hi. suppose a dll contains the following functions extern "C" __declspec(dllexport) void f(bool x) { //do something } extern "C" __declspec(dllexport) const char* g() { //do something else } My first naive approach to use these functions from C# was as follows: [DllImport("MyDll.dll")] internal static extern void f(bool x); [Dl...

C# interop to XPCOM

Before asking my question, I should admit that my knowledge of .NET interop is sparse, so I realize that I might be making a newbie error. I am using the GeckoFx library to create a C# application that contains an embedded Gecko (Firefox) browser instance. The app works well using GeckoFx in its original form, but I need to extend it to...

MarshalAs nested structure

I have two C++ structures that I have to send as parameters when calling a DLL method from C#. For example, lets define them as: struct A { int data; } struct B { int MoreData; A * SomeData; } A method that I need to call from C# has the following signature: int operation (B * data); (Please note that I do not have th...

Marshalling a C# Dictionary over COM interop to C++

Is there a good way of marshalling a Dictionary<string, string> over COM interop? Ideas so far include tokenising each KeyPair to an array of strings which can be marshalled as a SafeArray, or having two string arrays containing keys and values. Neither seems particularly satisfactory. Any ideas? ...

Marshal void* to array<byte>^

I am looking to write a void* buffer to a MemoryStream in a C++/CLI. As I don't think this is possible directly, alternatively I would like to convert this buffer to an array<byte>^ in order to be able to call Stream.Write(). I've looked at Marshal but then I am having trouble coverting void* to System::IntPtr. Any help is appreciated. ...

Can JAXB output an ArrayList as comma separated values?

I have something like @XmlElementWrapper(name="Mylist") List<Items> myItems = new ArrayList<Items>() and that comes out like <Mylist> <myItems>item 1</myItems> <myItems>item 2</myItems> <myItems>item 3</myItems> </Mylist> Is it possible to make this come out more like <Mylist> <myItems>item 1, item 2, item 3</myItems...

When to use RelaseComObject vs FinalReleaseComObject?

When should I use Marshal.FinalReleaseComObject vs Marshal.ReleaseComObject? Is there any danger in using Marshal.FinalReleaseComObject? ...

Display null for objects -JSON- JAXB

Hi All, I want to marshal null objects as null in the JSON representation. But, right now, Am not seeing the element in the JSON if the object is null. Example: @XmlAccessType(FIELD) @XmlType(name="foo" propOrder={"foo"} class foo{ @XmlElement private Integer foo; private Integer another_foo; .. getter() setter() } In m...

Passing a Structure to C++ API using Marshal.StructureToPtr in C#

Hi, I am using API written in C++ in my code (writting in C#). API requires a parameter as Pointer to Structure. The Structure cosists of "Int"s and Char Arrays: for example unsafe public struct ToBePassed { Int32 Num1; Int32 Num2; Char[] Data; // or fixed Char Data[255]; } I can not directly pass...

Default IMarshal implementation?

I am trying to implement registry-free COM explicilty in my code (can't use registry-free COM via an app manifest since that only works on the exe level): I create a static class that loads the COM dll, calls DllGetClassObject, then IClassFactory::CreateInstance(). Works just fine to a point. Implementation details are at http://www.dim...

C# Marshalling char** and unsigned char**

Hello, all. Here is the problem - i have some C image processing library that i need to use from C# application. Lack of experience with DllImport strikes me hard for now. The function i need to use looks like: IMAGEPROCESS_API const int importImage ( const unsigned char* image, const char* xmlInput, ...

How to Marshall C++ Native Objects to Managed C++ CLI

Hello, I have bunch of native C++ objects and classes contains DTL maps, maps of maps and lists and vectors. I need to call managed C++ functions from C++ native code and need to pass these native objects and STL containers(lists,maps , maps of maps) to C++/CLI. It needs to marshal or some how serialize these objects. How can I do that...

Does marshaling a marshaled interface give me a marshaller to the proxy or the original interface?

Here is a concrete example: I create a IWeBrowser2 interface by calling wb.CoCreateInstance(CLSID_InternetExplorer, 0, CLSCTX_SERVER);. This gives me a marshaled interface from my process into whichever of the running iexplore.exe processes happens to contain this browser tab in my thread A. Now I use the IGlobalInterfaceTable to get a...

Marshall an array of structs

I am calling a C++ function from C#. As arguments it receives a pointer to an array of structs. struct A { int data; } int CFunction (A* pointerToFirstElementOfArray, int NumberOfArrayElements) In C# I have created the same struct (as a class) and I marshall it correctly (the first element in the array is received correctly). He...

How to pass COM pointer from one process to another?

I have an interface pointer to an COM object sitting within process 1. I would like to get access to the same object from another process. How can I achieve this purpose? I believe directly passing over the pointer wouldn't work due to different address spaces. I know it involves the marshaling/proxy/stub stuff. But I don't know details....

.Net Compact Framework - Calling ActiveX Object that uses [out] SAFEARRAY(float) *

In the Compact Framework 3.5, I am attempting to call an ActiveX object that has an IDL function signature: HRESULT MyFunc([out] SAFEARRAY(float) *var) The Interop generation creates the msil [out] class [mscorlib]System.Array& marshal( safearray float32) Which seems reasonable enough, but I keep getting a "NotSupportedException"...

Convert C uint8_t pointer to C# byte array

Hi, I have exported the following C function to be invoked in a DLL file. uint8_t* _stdcall GetCurrentImage(); Now I want to call this function in C# to get a bitmap Image. How can I do this? Thanks in advance! ...