marshalling

Is it possible to use @XmlInverseReference where object and property are of same type?

前提是你 提交于 2020-01-24 13:08:08
问题 I'm using the MOXy JAXB implementation and make quite extensive use of the @XmlInverseReference annotation. However, I've recently encountered a scenario where this approach doesn't seem to work. If I have a class containing a field with a property that's the same type as the parent class, applying @XmlInverseReference seems to suppress the marshalling of that property altogether. Omitting the annotation yields a predictable StackoverflowException. Has anybody encountered this problem and

Error: Calling C++ dll function in C#

China☆狼群 提交于 2020-01-24 09:29:33
问题 I am trying to use functions in C++ dll from C#, but I got an error: "attempt to read or write protected memory. This is often indication that other memory is corrupt" Anyone know how to fix ? Here is C++ functions: typedef void *DGNHandle; __declspec(dllexport) DGNHandle CPL_DLL DGNOpen( const char *, int ); __declspec(dllexport) DGNElemCore CPL_DLL *DGNReadElement( DGNHandle ) Here is structure in C++: typedef struct { int offset; int size; int element_id; /*!< Element number (zero based) *

Encoding/Decoding multi-type fields in JSON golang

China☆狼群 提交于 2020-01-24 00:45:10
问题 I am trying to create a struct where a field can hold data of a few particular types, say int , string and a CustomType . I want to decode/encode this struct to/from JSON. How can we achieve this in go/golang? For example, I have a struct for the following definition: type MyData struct { Name string `json:"name"` Value int32 `json:"value"` Param <can be either int, string or CustomType> `json:"param"` } Where CustomType is type CustomType struct { Custom bool `json:"custom"` } Let's say I

Encoding/Decoding multi-type fields in JSON golang

允我心安 提交于 2020-01-24 00:45:10
问题 I am trying to create a struct where a field can hold data of a few particular types, say int , string and a CustomType . I want to decode/encode this struct to/from JSON. How can we achieve this in go/golang? For example, I have a struct for the following definition: type MyData struct { Name string `json:"name"` Value int32 `json:"value"` Param <can be either int, string or CustomType> `json:"param"` } Where CustomType is type CustomType struct { Custom bool `json:"custom"` } Let's say I

Marshalling C dll code into C#

一世执手 提交于 2020-01-23 12:13:14
问题 I have the following C-code signature in a dll: extern __declspec(dllexport) unsigned char * funct_name (int *w, int *h, char **enc, int len, unsigned char *text, int *lp, int *mp, int *ep) The C function can modify w, h, enc, lp, mp, and ep (though the latter three can be null and it won't do anything. I'm using the following in C# [DllImport("iec16022ecc200.dll", EntryPoint = "iec16022ecc200", ExactSpelling = false, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention

How To Marshal Return Values Of WinApi Functions?

痞子三分冷 提交于 2020-01-21 07:51:06
问题 Simple: How can I explicitly marshal the result of a WinAPi function ? I know how to marshal parameters of WinApi functions in C# but how can I also marshal the return values ? Or do I actually have to marshal them ? I understand WinAPi returns only BOOL or all types of INT (handles are int as well in unmanaged code). // common signature [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)] static extern int GetFileAttributes([MarshalAs(UnmanagedType.LPStr)] string filename

Calling C# From Unmanaged C++ Passing Or Returning “Complex” Types

做~自己de王妃 提交于 2020-01-16 05:02:59
问题 I'm after help on how to use complex objects either as return values or passed as parameters to C# class methods exposed to unmanaged C++ as COM components Here's why: I'm working on a project where we have half a dozen unmanaged C++ applications that each directly access the same Microsoft SQL Server database. We want to be able to use MS-Sql/Oracle/MySql with minimum changes and we've decided to implement a business logic plus data layer exposed via WCF services to get the required

How can I copy a array of strings into an unmanaged char double pointer?

↘锁芯ラ 提交于 2020-01-15 15:42:03
问题 I have a char** in a C struct which is allocated in the C code as a Nx128 matrix. In C# I have an array of strings and I want to copy this array to the char double pointer, without reallocating anything. I tried this: public void StringArrayToPtr(IntPtr ptr, string[] array) { for (int i = 0; i < array.Length; i++) { char[] chars = (array[i] + '\0').ToCharArray(); Marshal.Copy(chars, 0, IntPtr.Add(ptr, 128*i), chars.Length); } } But this doesn't work. Does somebody know how to perform such a

How can I copy a array of strings into an unmanaged char double pointer?

筅森魡賤 提交于 2020-01-15 15:39:38
问题 I have a char** in a C struct which is allocated in the C code as a Nx128 matrix. In C# I have an array of strings and I want to copy this array to the char double pointer, without reallocating anything. I tried this: public void StringArrayToPtr(IntPtr ptr, string[] array) { for (int i = 0; i < array.Length; i++) { char[] chars = (array[i] + '\0').ToCharArray(); Marshal.Copy(chars, 0, IntPtr.Add(ptr, 128*i), chars.Length); } } But this doesn't work. Does somebody know how to perform such a

Tutorial needed on invoking unmanaged DLL from C#.NET

痴心易碎 提交于 2020-01-15 09:15:34
问题 I have a DLL from a vendor that I Need to invoke from C#. I know that C# data classes are not directly compatible with C++ data types. So, given that I have a function that receives data and returns a "string". (like this) string answer = CreateCode2(int, string1, uint32, string2, uint16); What must I do to make the input parameters compatible, and then make the result string compatible? Please - I have never done this: Don't give answers like "Use P/Invoke" or "Use Marshal" I need a tutorial