FAQ Database Discussion Community


How to marshall large java objects to xml without heap error?

java,xml,jaxb,marshalling
Currently I am using JAXB marshaller to marshall the lasrge java object and it is working but when i recive the large java object application is throwing the OutOfMemoryError: heap space error. Can some one let me know how to marshall large java object to xml without heap error. StringWriter...

const char* in C#?

c#,.net,dll,pinvoke,marshalling
I try to call a plain C-function from an external DLL out of my C#-application. This functions is defined as void set_param(const char *data) Now I have some problems using this function: How do I specify this "const" in C#-code? public static extern void set_param(sbyte *data) seems to miss the...

Marshaling strings to unmanaged memory, passing them to c++ and return back to c# again

c#,marshalling
I am creating unmanaged memory block in c# and fill it with data from structs. I iterate through the list of structs and do something like this: Marshal.StructureToPtr(structTemp, currentMemoryPosition, false); currentMemPosition = new IntPtr(currentMemPosition.ToInt64() + structSize); The struct contains reference type: "string". I've looked into BOL for a StructureToPtr method...

Golang Struct Won't Marshal to JSON [duplicate]

json,struct,go,marshalling
This question already has an answer here: My structures are not marshalling into json 1 answer I'm trying to marshal a struct in Go to JSON but it won't marshal and I can't understand why. My struct definitions type PodsCondensed struct { pods []PodCondensed `json:"pods"` } func (p *PodsCondensed)...

Problems when P/Invoking CertCreateSelfSignCertificate

c#,.net,pinvoke,marshalling,x509certificate2
I was following this article (in it there is a link to a .cs file at the bottom of the page) to generate a self-signed X509Certificate2. The code in the article works but now I want to extend it. I am trying to pass the optional argument, _In_opt_ PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,...

How to pass Array of doubles from C# to C++ (DLL)

c#,c++,pinvoke,marshalling,dllimport
the C++ function signature is: int Eye_GetPositionSC2(std::string fname_mob, double sensors[9], int &map_x, int &map_y) the C# function signature is: [DllImport(@"eyeWhere.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)] public static extern int Eye_GetPositionSC2([MarshalAs(UnmanagedType.LPWStr)]string filename, [In , MarshalAs(UnmanagedType.LPArray)]double[] sensors) the code is compiling good but there is an "AccessViolationexception" while passing the double...

How can I marshal a Delphi short string using p/invoke?

c#,delphi,pinvoke,marshalling
I have a problem with a variable type from a dll which i am importing in C#. It is written in object oriented pascal and it says it is developed with the Delphi Development Tool. On the manual of the library it says that shortstring is a packed array of...

Ruby Marshal.dump gives different results for what looks like the same thing

ruby,serialization,marshalling
I'm seeing slightly different results with Ruby's Marshal.dump depending on if I called .to_s on something or I typed in the characters. I'm really not clear on what's happening here: » Marshal.dump(1.to_s) => "\x04\bI\"\x061\x06:\x06EF" » Marshal.dump('1') => "\x04\bI\"\x061\x06:\x06ET" » 1.to_s == '1' => true So although it appears that 1.to_s...

How to obtain the runtime type from an object in java

java,jaxb,marshalling
I have this code: public void doSomething(Integer param){ . . . JAXBElement<Integer> jaxb = new JAXBElement<Integer> (new QName("uri","local"),Integer.class, param); . . . } And I want it to be more flexible. I need the parameter to be of type Object, but I don't know how to change this line: JAXBElement<what_do_I_put_here>...

Reading Byte Array From Delphi Pointer In C#

c#,delphi,pinvoke,marshalling,intptr
I have asked question before. Call Delphi Function From C# I have added two methods like this. C# public interface IStringFunctions { [MethodImplAttribute(MethodImplOptions.PreserveSig)] void SetValueAsByteArray(IntPtr DataPointer, int DataLength); [MethodImplAttribute(MethodImplOptions.PreserveSig)] IntPtr GetValueAsByteArray(out int DataLength); } if (instance != null) { // Sending Pointer of Byte Array To Delphi Function. byte[] inputBytes...

C# code calling C++/CLI class method - new instance still has old instance values

c#,memory-leaks,c++-cli,marshalling,destructor
I am a newbie in terms of working with both C# and C++/CLI code together. In my C# code, I am creating a new instance of a class FooClass and running a method FooClass:ParseCmdArgs, which takes in a System::String, converts to a std::string, and then pushes to a vector "bars"...

Crash C# Application using Marshalling

c#,c++,dll,marshalling,vhosts
I created a C# application which use 2 C++ Dll, the first one work very well, but i have some trouble with the second. I'm flashing a CPU : My dll : [DllImport(@"st10flasher.dll")] public static extern long SetCom(string PortName, long comspeed); [DllImport(@"st10flasher.dll")] public static extern long LoadFile(string FileName, ref long...

reconstruct python method with kwargs with marshal and types?

python,serialization,deserialization,marshalling,unmarshalling
I am using the marshal module to serialize some Python methods, and reconstruct them using types module (Is there an easy way to pickle a python function (or otherwise serialize its code)?). I am having trouble getting it to work with optional kwargs. E.g. import marshal import types def test_func(x,...

XMLGregorianCalendar not displayed in the right format when marshalled

java,xml,date,jaxb,marshalling
I'm getting some dates from the database, putting them into objects of classes derived from an XSD schema using JAXB and then marshalling the objects to an XML file. One of the derived classes has an XMLGregorianCalendar field, and I want the date that I put there to be written...

Get object reference name in Java for constructing XML

java,xml,marshalling
I am writing custom XML marshaller using XML generators. I am stuck with tag names writing. Example: List<String> userList = new ArrayList<String>(); userList.add("UserA"); userList.add("UserB"); Map<String, Object> systemMap = new HashMap<String, Object>(); systemMap.put("SystemA",userList); My requirement is: <SystemA> <userList> [userA,userB] </userList> </SystemA> ...

Byte array Marshalling

c#,c++,marshalling
My application is receiving a struct from another application via UDP socket. The other application is written in C++. The struct has variables of different types. On my application side, I decode the received message from byte array to the desired type and put it in a Dictionary type variable...

how to retrieve values from pointer to array of ULONG in C#

c#,c++,pointers,marshalling,intptr
Structure in C++: typedef struct _denom { CHAR cCurrencyID[3]; int ulAmount; short usCount; LPULONG lpulValues; //pointer to array of ULONGS int ulCashBox; } DENOMINAT, * LPDENOMINAT; Structure in C#: [ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack=1 ) ] public struct DENOMINAT { [ MarshalAs( UnmanagedType.ByValArray, SizeConst=3 ) ] public char[] cCurrencyID; public...

Overhead - Calling C++ function from C#

c#,c++,pinvoke,marshalling
I am calling two C++ functions from C#. While doing that in a iteration for around 1 million call i am seeing a overhead of about 30%. C++ function : EXTERN_C void STDAPICALLTYPE FunctionA(UINT_PTR mathId) { ... ... } In my C# assembly dll as : [DllImport("CPlusPlus.dll")] public static extern...

Unmarshaling XML in Go with Conflicting Element Names

xml,encoding,go,marshalling,unmarshalling
I have the following XML, externally defined and outside of my organization's control: <foo> <bar> <zip>zip</zip> </bar> <bar> <zap>zap</zap> </bar> </foo> I am using these structs: type Foo struct { XMLName xml.Name `xml:"foo"` Bar1 Bar1 Bar2 Bar2 } type Bar1 struct { XMLName xml.Name `xml:"bar"` Zip string `xml:"zip"` } type...

C# string to Inno Setup

c#,interop,marshalling,inno-setup
I have a C# DLL in which exposes a method which generates a string. I want to call this Method from Inno Setup and receive the string then. function GetInformationEx():String; external 'GetInformationEx@{src}\data\tools\ZipLib.dll stdcall loadwithalteredsearchpath'; procedure ShowProgress(progress:Integer); var information : String; begin WriteDebugString('ShowProgress called'); if(progress > pbStateZip.position) then begin pbStateZip.position :=...

Marshalling float Array to c#

c#,c++,marshalling
I'm trying to marshal a struct that contains a float-Array from a C++ DLL to C#. I created the C++ DLL from the following code: //MarshalTest.h namespace mTest{ typedef struct { float data[3]; int otherStuff; } dataStruct; extern "C" __declspec(dllexport) dataStruct getData(); } //MarshalTest.cpp #include "MarshallTest.h" using namespace std; namespace...

Marshal's [In] [Out] Attributes

c#,pinvoke,marshalling,dllimport
I'm invoking an unmanaged function in my C# code. The declaration of this function is as follow: int myFun(unsigned char* inputBuffer, unsigned char* &outputBuffer); I use this function as follow: [DllImport("myDLL.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int myFun([In] byte[] inputBuffer, out IntPtr outputBuffer); byte[] a = Encoding.ASCII.GetBytes("sampletext!"); IntPtr b;...

What does N in jsonFormatN in spray mean?

json,marshalling,spray
I'm looking at the code of "Akka and Spray" tutorial in Typesafe's Activator, written by eigengo. I do not get where jsonFormat1, jsonFormat2, ... jsonFormatN is defined and how it does what it does. implicit val sendMessageFormat = jsonFormat2(SendMessage) The above snippet is in scala > api > MessengerService.scala Thank...

Marshal struct in struct from c# to c++

c#,c++,marshalling
I have the following structures in C# and C++. C++: struct TestA { char* iu; }; struct TestB { int cycle1; int cycle2; }; struct MainStruct { TestA test; TestB test2; }; C#: [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi, Pack = 1)] internal struct TestA { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 36)] private string iu; public...

Can't serialize org.dom4j.Document using JBoss Marshalling API

java,serialization,jboss,marshalling,dom4j
I'm hitting into an issue when trying to serialize a Java object with org.dom4j.Document as an attribute using JBoss Marshalling API. I'm using JDK 1.7 Same issue with dom4j 1.5.2. Java Object : package test.t4; import org.dom4j.Document; public class Movie implements java.io.Serializable { private static final long serialVersionUID = 1L;...

jaxb marxshalling - duplicate elements in the xml

jaxb,marshalling
I have two objects that are in hierarchical relationship. I have the jaxb mapping for setter methods in the child pojo. While loading the xml into pojo I don't have any issues. However, while generating the xml, I see two element entries in the xml for the same attribute in...

Call Delphi Function From C#

c#,delphi,pinvoke,delphi-xe2,marshalling
I have a below DLL source code. library Project1; uses System.SysUtils, System.Classes; type IStringFunctions = interface ['{240B567B-E619-48E4-8CDA-F6A722F44A71}'] function GetMethodValueAsString():PAnsiChar; stdcall; end; TStringFunctions = class(TInterfacedObject, IStringFunctions) public function GetMethodValueAsString():PAnsiChar; stdcall; end; {$R *.res} function TStringFunctions.GetMethodValueAsString():PAnsiChar; stdcall; begin Result := 'test'; end; procedure GetImplementation(out instance:IStringFunctions); stdcall; export; begin...

NodeSeqMarshaller with ContentType charset not resolving

scala,character-encoding,marshalling,spray
Attempting to get a spray endpoint negotiating a postman request for content. My XML marshaller seems to let me down, ie, it never resolves the correct marshaller option based on Accept header and charset. I have the following: object ResponseVO { val NodeSeqMarshaller = Marshaller.delegate[ResponseVO, NodeSeq](ContentType(`text/xml`, `UTF-8`)) { respVO =>...

How to marshal C++ struct containing DWORD bitfields in C#

c#,c,struct,marshalling,bit-fields
I'm working with an unmanaged SDK and have a struct that I am needing to marshal in C#: struct DEV_TIME { DWORD second:6; DWORD minute:6; DWORD hour:5; DWORD day:5; DWORD month:4; DWORD year:6; } I've searched around and have tried a number of things but can't seem to figure it...

What is the best way to wrap unmanaged C++ classes so they can be consumed by .Net managed client applications?

c++,.net,pinvoke,marshalling
We have a win32 C++ unmanaged library (which calls Boost and openCV under the covers). The library contains several public class definitions. The classes themselves expose several methods who's parameters include vectors, shared pointers and callbacks as part of their method signatures. We would like to create a wrapper which...

byte[] array to struct with variable length array

c#,struct,marshalling
I'm receiving an array of bytes from a socket and the structure of the bytes is simply a large char array of fixed width strings. In some cases, the last field is dynamic (instead of fixed length) and I'm trying to Marshal the bytes to a struct. I've read that...

Which objects do I need to explicitly release when calling Windows API functions from C#?

c#,winapi,pointers,marshalling
I am using the following code to call a winapi function from C#. [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] public static extern IntPtr PathFindFileName(string p); IntPtr pStr = PathFindFileName("Test"); string str = Marshal.PtrToStringAuto(pStr) I would like to know how to distinguish between objects that require releasing once done, and objects that do...

Marshal to std::string from System::String^ member of struct handle

.net,c++-cli,marshalling
I am trying to marshal to a std::string from a System::String^. Usually this can be done with the marshal_as<T> template i.e. System::String ^managedString = "test"; std::string stdString = marshal_as<std::string>(managedString); But if the String^ is part of a struct that is accessed by reference i.e. value struct SomeStruct { String ^managedString;...

How to embed a method result into JSON output when marshalling a type?

json,struct,go,marshalling
I'm seeking a clean approach to embed the return value of a method into the JSON marshalling of a type/value. It would be great if I don't need to write custom JSON marshaller. For example, if the User type has FirstName and LastName fields and a FullName() method, how can...

Set MOXy as JAXB Provider without properties file in the same package

java,json,jaxb,marshalling,moxy
I am trying to use MOXy as my JAXB provider in order to marshal/unmarshal content into XML/JSON. I have created the "jaxb.properties" file with as content : javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactor Everything works fine. JAXBContext jaxbContext = JAXBContext.newInstance(ServerInformation.class); // The jaxb.properties must be in the same package as "ServerInformation.java" Marshaller marshaller = jaxbContext.createMarshaller();...

Calling C# function from a C++/CLI function

c#,c++,c++-cli,interop,marshalling
My project requires me to use C# to provide a user interface to C++. One of the C++ function I call does a bunch of work and provides periodic progress updates through another "object." Here's a example of what I mean. C++ class AppDelegate : public ProgressDelegate { void AppDelegate::UpdateStatusText(const...

Akka-Spray object marshall

json,scala,akka,marshalling,spray
I am experimenting with aka and spray, what I want to achieve is a simple object marshalling service. When I try to compile the code I get the following error : Error:(33, 18) could not find implicit value for parameter marshaller: spray.httpx.marshalling.Marshaller[ExampleApplication.Password] marshal(Password(randomString(8),i,0)) ^ Here is the code: import akka.actor.ActorSystem...