marshalling

Conversion in .net: Native Utf-8 <-> Managed String

半城伤御伤魂 提交于 2020-01-10 10:17:49
问题 I created those two methods to convert Native utf-8 strings (char*) into managed string and vice versa. The following code does the job: public IntPtr NativeUtf8FromString(string managedString) { byte[] buffer = Encoding.UTF8.GetBytes(managedString); // not null terminated Array.Resize(ref buffer, buffer.Length + 1); buffer[buffer.Length - 1] = 0; // terminating 0 IntPtr nativeUtf8 = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length); return nativeUtf8; }

Conversion in .net: Native Utf-8 <-> Managed String

倖福魔咒の 提交于 2020-01-10 10:17:08
问题 I created those two methods to convert Native utf-8 strings (char*) into managed string and vice versa. The following code does the job: public IntPtr NativeUtf8FromString(string managedString) { byte[] buffer = Encoding.UTF8.GetBytes(managedString); // not null terminated Array.Resize(ref buffer, buffer.Length + 1); buffer[buffer.Length - 1] = 0; // terminating 0 IntPtr nativeUtf8 = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, nativeUtf8, buffer.Length); return nativeUtf8; }

Copying bytes from Bitmap to byte array and back with Marshall.Copy doesn't work right

帅比萌擦擦* 提交于 2020-01-07 08:33:19
问题 I want to copy bytes with Marshall.Copy. My code work, but bytes is strange for me. I think, I got indexes not real bytes. If this compute and save back, I got different colors in image with lot bigger byte size (image size is same). Bitmap bmp = new Bitmap(imagepath); Width = bmp.Width; Height = bmp.Height; byte[] data; BitmapData bdata; switch (bmp.PixelFormat) { case PixelFormat.Format8bppIndexed: { data = new byte[Width * Height]; bdata = bmp.LockBits(new Rectangle(0, 0, Width, Height)

Copying bytes from Bitmap to byte array and back with Marshall.Copy doesn't work right

故事扮演 提交于 2020-01-07 08:33:07
问题 I want to copy bytes with Marshall.Copy. My code work, but bytes is strange for me. I think, I got indexes not real bytes. If this compute and save back, I got different colors in image with lot bigger byte size (image size is same). Bitmap bmp = new Bitmap(imagepath); Width = bmp.Width; Height = bmp.Height; byte[] data; BitmapData bdata; switch (bmp.PixelFormat) { case PixelFormat.Format8bppIndexed: { data = new byte[Width * Height]; bdata = bmp.LockBits(new Rectangle(0, 0, Width, Height)

Cannot get interface from different process via ROT

旧时模样 提交于 2020-01-07 07:01:18
问题 my app is an .exe, it registers itself to ROT. [ComVisible(true)] [ProgId("My.App")] public class MyApp { public Interop_MyApp.IXXX XXX { get { return XXXImpl.Instance; } // -> Instance is derived from Interop_MyApp.IXXX, and static } public MyApp() { } }; I start the .exe above, it's running. Then I start an other .exe, which tries to get the XXX. object o = Marshal.GetActiveObject("My.App"); // -> returns a __ComObject, fine if (o == null) throw new InvalidOperationException("Could not

How to customize automatic marshaling in Spring RestTemplate to produce/modify XML headers (encoding, DOCTYPE)

允我心安 提交于 2020-01-07 04:38:10
问题 I'd like to find how to influence how Spring automatically marshals Java objects to XML when sending a POST request via RestTemplate . Particularly, how to configure what is in the XML headers ( encoding , DOCTYPE , ...). There are plenty of questions closely touching the topic (Include DOCTYPE for Spring Jaxb2Marshaller, How to add DOCTYPE and xml processing instructions when marshalling with JAXB?, how to add DOCTYPE in jaxb marshaller, How to declare doctype ,xml version and encoding in

Sending/receiving objects over network in java

情到浓时终转凉″ 提交于 2020-01-06 19:30:55
问题 I am implementing new client server app. I would like to ask, What is the best way to send and receive objects via network? On server side , I have something like this but I am getting null pointer exception: @RequestMapping(value = "/test") @ResponseBody public Student myAction(){ Student student = new Student(1,"Miso"); return student; } On client side: public Student test(){ String prodGroup = ""; Student obj = null; try { url = new URL("http://localhost:8080/getData/test"); urlConn =

C# calling C++ 3rd party DLL (no source) raises exception - not PInvoke Compatible

岁酱吖の 提交于 2020-01-06 16:22:26
问题 I am using VS 2015 Community with an ASP.NET MVC Web Application that uses a 3rd party C++ DLL I do not have source code for. Documentation is very scarce as is any helpful communication with the authors of the 3rd party DLL. I've asked a related SO Question and received a good answer from @Steven. I've modified my code according to his answer and am trying to make a successful call to the 3rd party C++ DLL. The code: // Call DLL MyDLLInput _DLLInput = new MyDLLInput(); { SomeList = new int

Marshal/Unmarshal int type

末鹿安然 提交于 2020-01-06 06:01:30
问题 I use an int type to represent an enum. I want to convert it to string when I marshal it to JSON, AFAIK, I should implement UnmarshalJSON and MarshalJSON , but it complains: marshal error: json: error calling MarshalJSON for type main.trxStatus: invalid character 'b' looking for beginning of valueunexpected end of JSON input when marshalling. Then I've add the quotes to the marshalled string: func (s trxStatus) MarshalJSON() ([]byte, error) { return []byte("\"" + s.String() + "\""), nil } the

JAXB marshal to string works differently on different computers

情到浓时终转凉″ 提交于 2020-01-06 05:26:35
问题 I have this test java app: @XmlRootElement public class Car { @XmlElement(namespace="http://www.example.com/CAR_NAME") private String name; @XmlElement(namespace="http://www.example.com/CAR_PRICE") private int price; @XmlElement(namespace="http://www.example.com/CAR_BUS") private Bus bus; //constructors, getters and setters @XmlRootElement public class Bus { @XmlElement(namespace="http://www.example.com/BUS_NAME") private String name; @XmlElement(namespace="http://www.example.com/BUS_PRICE")