marshalling

Marshalling array of structs vs classes

荒凉一梦 提交于 2020-01-02 06:55:22
问题 I want to read a native struct into a C# type using Marshalling. My method to Marshal structs is like so: T ReadObject<T>(BinaryReader br) { var bytes = br.ReadBytes(Marshal.SizeOf(typeof(T))); var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { return (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); } finally { handle.Free(); } } Now this works fine in general, the problem arises with the following type: [StructLayout(LayoutKind.Sequential, Pack=1)] class SubData

Marshalling a Notification Parcel

时光怂恿深爱的人放手 提交于 2020-01-02 04:31:08
问题 I'm trying to write a Notification object to a File. The best way I could find was to write the object to a parcel, marshall that parcel to get a byte[] and then write it to a file. Parcel notif = Parcel.obtain(); notification.writeToParcel(notif, 0); byte[] notifArray = notif.marshall(); I get a Runtime exception when I try to marshall the parcel though: "Tried to marshall a Parcel that contained Binder objects." Is there a better way of writing Notification objects to file? Else, how do I

Return string[] in C# dll for VBA

試著忘記壹切 提交于 2020-01-01 14:20:32
问题 I've written this little C# test DLL using UnmanagedExports (obtained as a NuGet package), which is working fine. However, I'm wondering if, and if so how, it's possible to immediately return a String() array instead of returning a string which has to be Split() in a VBA wrapper function. That is to say, the point of interest is the method GetFilesWithExtension(). The other methods in the dll are just small tests I made while figuring out how to pass strings with the correct encoding. The DLL

Return string[] in C# dll for VBA

ぃ、小莉子 提交于 2020-01-01 14:20:21
问题 I've written this little C# test DLL using UnmanagedExports (obtained as a NuGet package), which is working fine. However, I'm wondering if, and if so how, it's possible to immediately return a String() array instead of returning a string which has to be Split() in a VBA wrapper function. That is to say, the point of interest is the method GetFilesWithExtension(). The other methods in the dll are just small tests I made while figuring out how to pass strings with the correct encoding. The DLL

How does Marshal.GetFunctionPointerForDelegate work on instance members?

眉间皱痕 提交于 2020-01-01 11:59:07
问题 I am wondering about Marshal.GetFunctionPointerForDelegate. Namely I want to know how it converts a delegate to a function that is non static into a function pointer. Does it dynamically generate a code stub that has the instance attached somehow? And if so, doesn't this leak memory? Perhaps the delegate frees it in its finalizer? It doesn't look like System.Delegate has a finalizer, so I am very interested in how this mechanism works. I would assume that it would take 4 bytes for the

How do I call an unmanaged function that has a char[] as OUT parameter from C#?

送分小仙女□ 提交于 2020-01-01 09:42:21
问题 Say, I've got that prototype of a function that is exposed on a DLL: int CALLBACK worker (char* a_inBuf, int a_InLen, char** a_pOutBuf, int* a_pOutLen, char** a_pErrBuf, int* a_pErrLen) I'm sure that it's ridiculously easy to call that DLL function from my C# code but it doesn't work with this code: [DllImport("mydll.dll")] public static extern int worker( [In, MarshalAs(UnmanagedType.LPArray)] byte[] inBuf, int inputLen, [Out, MarshalAs(UnmanagedType.LPArray)] byte[] outBuf, out int

JAXB in Netbeans Module

冷暖自知 提交于 2020-01-01 09:39:34
问题 Their Seems to be a problem when i attempt to run JAXB marshaller in a netbeans module. Originally I thought it was the node implimentation so i spent a couple of days reorganizing everything however I was still recieveing the odd error message javax.xml.bind.JAXBException: ClassCastException: attempting to cast jar:file:/C:/Program%20Files/jmonkeyplatform/ide/modules/ext/jaxb/api/jaxb-api.jar!/javax/xml/bind/JAXBContext.class to jar:file:/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/rt.jar!

C# Marshalled Callbacks

寵の児 提交于 2020-01-01 06:58:26
问题 I am trying to Marshall c call backs that are in a struct. I am pretty sure I have everything correct, but when using my C# example I don't get events, when using c++ I do get events. Here is the C# class Program { [DllImport("Some.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern int SetCallbacks(Callbacks callBack); static Callbacks Callback = new Callbacks { DataArrived = DataArrived, SendFailure = SendFailure }; static void Main(string[] args

Intercepting method calls in C# using Proxies

纵然是瞬间 提交于 2020-01-01 05:49:26
问题 What I'm trying to do is to be able to intercept calls to an object's methods and properties for cross-cutting concerns. I'm using proxy-based AOP using ContextBoundObject . However this doesn't work for recursive method calls, The first call against the target will be intercepted by the proxy and successfully invoked, allowing me to do cross-cut here. However subsequent method calls from within the first method will stay within the target class and are not intercepted by the proxy as if no

Marshalling “EGLRenderResolutionScaleProperty” to ANGLE from C# using P/Invoke

夙愿已清 提交于 2019-12-31 04:37:07
问题 I am trying to get ANGLE working in C# using P/Invoke. Basically, I am creating a simple 2D surface, and then passing that off to skia (using SkiaSharp). Everything is working and all that, but I am having a problem marshalling PropertySet to the unmanaged code. This bit works fine: // the properties var props = new PropertySet(); props.Add("EGLNativeWindowTypeProperty", swapChainPanel); // the surface attributes int[] surfaceAttrs = { EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, EGL_TRUE, EGL