marshalling

Calling COM visible managed component from managed code through COM wrapper

Hi, I have a 3rd party component, lets say FIPreviewHandler to handle preview, which implements IPreviewHandler. FIPreviewHandler is implemented as a Managed Component, and uses the IPreviewHandler interface and related interfaces through means of an interop. FIPreviewHandler is registered using regasm.exe as COM. I have a client appli...

P/Invoke: How to know which type to marshall from!?

Is there a one-stop shop for determining which .Net types/attributes to use, given a native type? Example would look something like this: Native Type | .Net Type --------------------------------------- int | Integer int* | IntPtr (or is it ref int?) LPCSTR | [MarshalAs(Un...

Castor Lists Polymorphism

Hi, I have a quick Castor question. I would like to use Castor mapping to marshal a list of objects. These objects are of two different types, both extending the same abstract base class. I would like them to have different tags in the xml, but both be added to the same list. They also have slightly different fields. Is this possible? If...

Convert Java Object into a XML String using jaxb

I would like to convert a Java Object to a String containing the marshaled XML data. One of the ways I could find was to first marshal to a File and then read the file using BufferedReader to convert into a String. I feel this may not be the most efficient way, because the IO operations are performed twice (Once during marshaling and the...

Spring web service: easy way to un-marshall a bean to XML client side?

I am utilizing spring to do all of the marshalling/unmarshalling of my bean objects (via jaxb2Marshaller/WebServiceTemplate). For debugging purposes, I would like to be able to spit out the request/response XML. Does anyone know if this is possible? Thanks. ...

How to pass managed arrays by ref to unmanaged library?

I'm creating a managed C++/CLI DLL that wraps and makes available a single function that resides in a c++ static library. I got most of it working, except one persistent nagging point. Here's how the function looks like in my unmanaged lib's .h file. typedef struct { float a; float b; }MyStruct; bool GetData(float p1, float*...

The name 'Marshal' does not exist in the current context

I got the code below from the bitmapmixer sample (DirectShow.NET) and i tried to reimplement it. The original sample works fine. In my version when I try to compile i get errors. private void AddHandlers() { // Add handlers for VMR purpose this.Paint += new PaintEventHandler(Form1_Paint); // for WM_PAINT this...

Passing StringBuilder to PInvoke function

In one of the post Titled "Call a c++ method that returns a string, from c#" Its said that , to make the following Pinvoke to work change the C++ signature to as extern "C" REGISTRATION_API void calculate(LPSTR msg) C++ code extern "C" REGISTRATION_API void calculate(char* msg) C# code [DllImport("thecpp.dll", CharSet=CharSet...

How to pass Object array to unmanaged code?

I'm trying to pass an array of objects from C# to unmanaged C++, and nothing seems to work. The compiler won't let me pretend the array is an IntPtr. Casting the array to an IntPtr doesn't work. I've tried to pass the address of pinned data, but this didn't work either. I just need to pass a pointer to the beginning of the array, and...

C# struct to C++ Marshalling problem

Hi All. I'm invoking a C++ function from within C#. This is the function header in C++ : int src_simple (SRC_DATA *data, int converter_type, int channels) ; And this is the equivilent C# function : [DllImport("libsamplerate-0.dll")] public static extern int src_simple(ref SRC_DATA sd, int converter_type, int channels); This ...

Correct usage of DllImport

Suppose there is a c++ method int NativeMethod(double, double *) in a Native.dll. My first attempt at calling this method from managed code was (assuming I don't need to specify the entry point) [DllImport("Native.dll")] private static extern int NativeMethod(double inD, IntPtr outD); Then to use the DLL I did IntPtr x = Marshal.All...

How to marshal a struct into a UInt16 Array

I know that you can use code like this to marshal a structure into a byte array: public static byte[] StructureToByteArray(object obj) { int len = Marshal.SizeOf(obj); byte[] arr = new byte[len]; IntPtr ptr = Marshal.AllocHGlobal(len); Marshal.StructureToPtr(obj, ptr, true); Marshal.Copy(ptr, arr, 0, len); Marsha...

Java Web Start application gives MARSHAL exception when data loaded from database via remote EJB.

I have a Java Web Start application calling remote Java EE 5 EJBs to load in data from a database. When the data is returned from the EJB to the client, I get the following exception. Looking it up online, it seems that everyone gets this exception and everyone has a different solution for it. All of my entities (abstract or not) imple...

How to marshall c++ char* to C# string using P/INVOKE

Hey guys, I'm new to C++. I'm calling a C++ function from C# using a PINVOKE and wanting to get a string back as an out parameter. However I just get an empty string back. The int out parameter works fine. Importing: [DllImport ( @"UnamanagedAssembly.dll", CharSet = CharSet.Ansi)] public static extern int Activate(ref int numActivat...

Examples of creating a simple COM component using C++ in Visual Studio 2008

Hello, Does anyone know of any recent examples of how to create a simple COM component in C++ using Visual Studio 2008 so I can learn how to marshal different kinds of data between unmanaged and managed code, and back again. I've found a few tutorials that suggest a C++ ATL project, but project settings page no longer has the settings m...

C++ to C# conversion of SendMessage using COPYDATASTRUCT

I'm converting a C++ application into C# which has generally been fairly straight forward, but now I'm dealing with pointers and running into problems. This is the original C++ code ShockVideoInfo* pVideoInfo = new ShockVideoInfo; COPYDATASTRUCT cd; cd.dwData = bSelf ? SHOCK_REQUEST_SELFVIEW_WINDOW : SHOCK_REQUEST_MAINVIEW_WIND...

JAXB Java and XSD mapping

In one of my projects I use JAXB2 marshaller, having a contract-first web service I generate the objects from a XML Schema. Everything works just fine. But, I have a "code usability" issue. Let me give you an example. Schema: <xs:complexType name="personContractAlertListType"> <xs:sequence> <xs:element ref="PersonContrac...

Managed to unmanaged code call causes access violation... sometimes

This code causes the following exception, sometimes: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt" private static TOKEN_GROUPS GetTokenGroups(IntPtr tokenHandle) { var groups = new TOKEN_GROUPS(); uint tokenInfoLength = 0; uint returnLength; var res = Ge...

Is Intptr sufficient when marshalling for wrapping a c++ interface (all abstract) which works by passing interface handles?

I am trying to wrap an unmanaged c++ interface composed of several abstract structs (with all pure virtual methods) and a small factory namespace which returns handles (shared_ptrs) to these structs. It seems that, because of this, I might be able to get away with merely marshalling pointers through as System.IntPtr types (although them...

I want to call a C# delegate from C++ unmanaged code. A parameterless delegate works fine , but a delegate with parameters crashed my program.

The Following is code of a function from a unmanged dll. It takes in a function pointer as argument and simply returns value returned by the called function. extern __declspec(dllexport) int _stdcall callDelegate(int (*pt2Func)()); extern __declspec(dllexport) int _stdcall callDelegate(int (*pt2Func)()) { int r = pt2Func(); re...