tagged [marshalling]
Marshal.PtrToStructure throwing System.ArgumentException error
Marshal.PtrToStructure throwing System.ArgumentException error I'm attempting to get a KBDLLHOOKSTRUCT from a keyboard-hook's lParam. Unfortunately the PtrToS
- Modified
- 23 Jan at 19:26
Passing a Structure to C++ API using Marshal.StructureToPtr in C#
Passing a Structure to C++ API using Marshal.StructureToPtr in C# I am using API written in C++ in my code (writting in C#). API requires a parameter as Pointer to Structure. The Structure consists of...
- Modified
- 26 Jun at 19:6
P/Invoke, c#: unsigned char losing a byte
P/Invoke, c#: unsigned char losing a byte Im working towards a dll file for a software's SDK and i'm trying to call a function to get information about the host of the software. there are two unsigned...
- Modified
- 7 Jan at 09:54
Do I need to delete structures marshaled via Marshal.PtrToStructure in unmanaged code?
Do I need to delete structures marshaled via Marshal.PtrToStructure in unmanaged code? I have this C++ code: Then in C# I call the function thus: ``` [DllImport("MyDll.dll")] static extern void Alloca...
- Modified
- 30 Jan at 22:8
Convert array of structs to IntPtr
Convert array of structs to IntPtr I am trying to convert an array of the RECT structure (given below) into an IntPtr, so I can send the pointer using PostMessage to another application. ``` [StructLa...
- Modified
- 6 Jul at 11:33
Can I use SafeHandle instead of IntPtr?
Can I use SafeHandle instead of IntPtr? I've searched the internet far and wide but didn't find a good explanation. My question is pretty simple. I have a DLL which has a function called Initialize an...
- Modified
- 15 Aug at 16:22
The fastest way to check if a type is blittable?
The fastest way to check if a type is blittable? In my serialiser/deserialiser, I have the following snippet: ``` if (element_type.IsValueType && collection_type.IsArray) { try { GCHan...
- Modified
- 13 May at 19:42
Correct way to marshal SIZE_T*?
Correct way to marshal SIZE_T*? I have the following C++ function definition, which I am trying to call through PInvoke from managed code: My managed declaration looked as follows: Some of you may not...
- Modified
- 21 Aug at 00:13
How can I marshall a vector<int> from a C++ dll to a C# application?
How can I marshall a vector from a C++ dll to a C# application? I have a C++ function that produces a list of rectangles that are interesting. I want to be able to get that list out of the C++ library...
- Modified
- 30 Apr at 20:47
Marshal C++ struct array into C#
Marshal C++ struct array into C# I have the following struct in C++: And a function that I'm p/invoking into to get an array of 3 of these structures: In C++ I would just do something like this: ``` L...
- Modified
- 9 Oct at 17:27
Marshal.SizeOf throws ArgumentException on enums
Marshal.SizeOf throws ArgumentException on enums Consider this code: it throws the exception: > An unhandled exception of type 'System.ArgumentException' occurred in TestConsole.exeAdditional informa...
- Modified
- 27 Dec at 10:37
Reading a C/C++ data structure in C# from a byte array
Reading a C/C++ data structure in C# from a byte array What would be the best way to fill a C# struct from a byte[] array where the data was from a C/C++ struct? The C struct would look something like...
- Modified
- 7 Feb at 01:6
Detecting cross-thread marshaling by COM RCW objects in C#
Detecting cross-thread marshaling by COM RCW objects in C# I'm working in a large multithreaded C# application handling bunches of COM interop. The other developers and I have ample opportunity to acc...
- Modified
- 31 Aug at 03:41
How do I marshall a pointer to a pointer of an array of structures?
How do I marshall a pointer to a pointer of an array of structures? My C declarations are as follows: My C# declarations are as follows: ``` [DllImport("myData.dll", EntryPoint = "myData")] public
- Modified
- 30 May at 19:35
Runtime callable wrapper (RCW) scope - process or application domain?
Runtime callable wrapper (RCW) scope - process or application domain? What is the scope of Runtime Callable Wrapper (RCW), when referencing unmanaged COM objects? According to the docs: > The runtime ...
- Modified
- 23 Jun at 14:2
C# Marshalling double* from C++ DLL?
C# Marshalling double* from C++ DLL? I have a C++ DLL with an exported function: The function calculates the FFT of the two double arrays (real and imaginary) an returns a single double array with the...
- Modified
- 21 Feb at 23:46
Non-blittable error on a blittable type
Non-blittable error on a blittable type I have this struct and this code: ``` [StructLayout(LayoutKind.Sequential, Pack = 8)] private class xvid_image_t { [MarshalAs(UnmanagedType.ByValArray, SizeCo...
- Modified
- 20 Jun at 09:12
Conversion in .net: Native Utf-8 <-> Managed String
Conversion in .net: Native Utf-8 Managed String 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 IntP...
- Modified
- 27 May at 12:19
How to return a vector of structs from Rust to C#?
How to return a vector of structs from Rust to C#? How is it possible to write Rust code like the C code below? This is my Rust code so far, without the option to marshal it: ``` pub struct PackChar {...
- Modified
- 22 Jun at 14:3
How to pass C# array to C++ and return it back to C# with additional items?
How to pass C# array to C++ and return it back to C# with additional items? I have a C# project which is using a C++ dll. (in visual studio 2010) I have to pass a array of int from C# code to C++ func...
- Modified
- 17 May at 15:31
C# to C++ process with WM_COPYDATA passing struct with strings
C# to C++ process with WM_COPYDATA passing struct with strings From a c# program I want to use WM_COPYDATA with SendMessage to communicate with a legacy c++/cli MFC application. I want to pass a manag...
- Modified
- 8 Oct at 10:8
Marshalling .NET generic types
Marshalling .NET generic types Here is a C# program that tries `Marshal.SizeOf` on a few different types: ``` using System; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] ...
- Modified
- 17 Oct at 17:24
WinApi - GetLastError vs. Marshal.GetLastWin32Error
WinApi - GetLastError vs. Marshal.GetLastWin32Error But I found no disadvantages of those 2! But see the accepted answer. --- I read [here](http://blogs.msdn.com/b/adam_nathan/archive/2003/04/25/56643...
- Modified
- 18 Jul at 09:14
How can I prevent CompileAssemblyFromSource from leaking memory?
How can I prevent CompileAssemblyFromSource from leaking memory? I have some C# code which is using CSharpCodeProvider.CompileAssemblyFromSource to create an assembly in memory. After the assembly has...
- Modified
- 23 May at 12:10
Marshal.PtrToStructure (and back again) and generic solution for endianness swapping
Marshal.PtrToStructure (and back again) and generic solution for endianness swapping I have a system where a remote agent sends serialized structures (from an embedded C system) for me to read and sto...
- Modified
- 12 Apr at 17:1