marshalling

How can I pass in a pointer to a pointer of a UInt16 array to a Marshalled function?

孤街浪徒 提交于 2019-12-14 02:32:10
问题 I'm attempting to send a pointer to a pointer of a UInt16 array to a marshalled function like so in C#: C++: int foo(Unsigned_16_Type** Buffer_Pointer); C#: [DllImport("example.dll")] public static extern int foo(IntPtr Buffer_Pointer); UInt16[] bufferArray = new UInt16[32]; IntPtr p_Buffer = (IntPtr)Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(UInt16)) * bufferArray.Length); Marshal.Copy(bufferArray, 0, p_Buffer, bufferArray.Length); //Issue is here GCHandle handle = GCHandle.Alloc(p_Buffer,

How do I successfully work with structures and nested structures within a cpp dll in VB.NET/C#?

你。 提交于 2019-12-14 02:26:58
问题 I want to call a DLL function that wants a structure, and within that structure is another structure. The Dll should return values to my structures but I get nothing but error codes. One time (some coding back ago) I successfully returned "True" on my function call, but there were no values in my structures. I am not very familiar with marshaling and such, but if someone could please provide me an example on how to do this! The Dll code looks like this:

Understanding VBByRefStr in VB.NET P/Invoke declarations

∥☆過路亽.° 提交于 2019-12-14 01:53:01
问题 When trying to use a P/Invoke declaration made in a VB.NET assembly from C# I noticed that string arguments become ref string arguments. A closer inspection reveals that e.g. Public Declare Unicode Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueW" ( _ ByVal hKey As IntPtr, ByVal lpValueName As String) As UInteger is compiled to [DllImport(...)]public static extern uint RegDeleteValue( IntPtr hKey, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpValueName); On MSDN I read:

Can JAXB output an ArrayList as comma separated values?

懵懂的女人 提交于 2019-12-14 01:04:54
问题 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> </Mylist> Since the data I am after is all just textual anyway? 回答1: You can use @XmlList to make it a space separated value. For a comma separated list you will need to use an

Marshal array of doubles from c to c#

怎甘沉沦 提交于 2019-12-13 23:15:54
问题 Can someone please tell me exactly what I should write to marshal an array of double pointers between C and C#? struct foo { double *abc[20]; }; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public class foo { // ??? abc; } I have had many oblique resonses to 2 previous queries, and I have read another dozen or so questions here on this same topic, but I can't find in any of them a simple answer to this question. 回答1: Ok, here is the simple, straightforward answer to this

C# Platform-invoke, c-style union with reference and value types

给你一囗甜甜゛ 提交于 2019-12-13 19:35:04
问题 I am trying to Marshall the following structure struct OpalMessage { OpalMessageType m_type; ///< Type of message union { const char * m_commandError; ///< Used by OpalIndCommandError OpalParamGeneral m_general; ///< Used by OpalCmdSetGeneralParameters OpalParamProtocol m_protocol; ///< Used by OpalCmdSetProtocolParameters OpalParamRegistration m_registrationInfo; ///< Used by OpalCmdRegistration OpalStatusRegistration m_registrationStatus; ///< Used by OpalIndRegistration OpalParamSetUpCall

Handling user-defined exceptions from C++ DLL - .NET PInvoke/Marshalling

限于喜欢 提交于 2019-12-13 19:11:47
问题 I am working on WPF application which internally calls a C/C++ DLL using PInvoke. In the debug mode of the DLL, whenever error occurs the function throw an exception which is basically a structure defined containing specific error message and application code specific to module. This is different from the normal Win32 error logging. Now my problem is I want to catch the exception thrown by the DLL. If in use a try catch around the Marshalled function, .NET just informed me saying something

Marshaling nested structures from C# to C++

北城余情 提交于 2019-12-13 17:58:12
问题 I have the following types in C++: typedef void* keychain_handle; typedef struct { const char* keyHolderName; unsigned int numKeys; key* keys; } key_holder; typedef struct { const char* keyName; unsigned int keySize; } key; And I have the following methos: int createKeyChain( int id, key_holder* keyHolders, keychain_handle* handle); I need my C# to create key holders with keys, send it to the C++ code and receive a handle. This is my C# code: /* Structs */ [StructLayout(LayoutKind.Sequential)

JAXB marshalling boolean into a complex type

℡╲_俬逩灬. 提交于 2019-12-13 15:12:37
问题 I am new in JAXB and I would like to do something i don't know if it's doable. I have a java class to marshall like this : @XmlAccessorType(XMLAccessType.NONE) public class MyClass { @XmlElement private String a = "x"; @XmlElement private String b = "xx"; @XmlElement private boolean c = true; ... } and want XML output like this : <?xml ...?> <MyClass> <a>x</a> <b>xx</b> <c value="true"/> </MyClass> One solution i have in mind is to use a boolean wrapper class to make it work, but i would like

PInvoke: Allocate memory in C++ and free it in C#

♀尐吖头ヾ 提交于 2019-12-13 13:26:30
问题 We are using PInvoke to interop between C# and C++. I have an interop struct as follows, with an identical layout C++ struct on the other side. [StructLayout(LayoutKind.Sequential)] public struct MeshDataStruct : IDisposable { public MeshDataStruct(double[] vertices, int[] triangles , int[] surfaces) { _vertex_count = vertices.Length / 3; _vertices = Marshal.AllocHGlobal(_vertex_count*3*sizeof (double)); Marshal.Copy(vertices, 0, _vertices, _vertex_count); } // .. extract data methods to