marshalling

C#: Marshalling a “pointer to an int array” from a SendMessage() lParam

一笑奈何 提交于 2019-12-31 04:17:53
问题 I'm trying to subclass an unmanaged statusbar window from my managed COM server using a class inherited from NativeWindow, and am running into a wall trying to make sense of how to properly marshal the contents of an lParam. http://msdn.microsoft.com/en-us/library/bb760757%28VS.85%29.aspx says that the contents of this lParam is of type (LPARAM)(LPINT) aWidths , and that the contents of this variable is actually a "pointer to an integer array." I can't figure out a way to marshal this

Get bitmap info from MPEG-2 Program / Transport Stream?

£可爱£侵袭症+ 提交于 2019-12-30 11:33:47
问题 In order to render a DirectShow graph in my WPF application, I use a sample grabber to write a bitmap to memory, and read it elsewhere in code. This may seem as a wierd solution, but seems to be the only way to get a WPF brush out of it. The following code gives me the information I need about the bitmap: AMMediaType mt = grabber.GetConnectedMediaType(); VideoInfoHeader header = (VideoInfoHeader)Marshal.PtrToStructure(mt.formatPtr, typeof VideoInfoHeader); header.BmiHeader // ... Now, header

I successfully called advapi32's LsaEnumerateAccountRights() from C#. Now how do I unmarshal the array of LSA_UNICODE_STRING it returns?

邮差的信 提交于 2019-12-30 09:24:11
问题 It's a pointer to an array of LSA_UNICODE_STRING structures. I found some code that does the inverse, i.e., create a LSA_UNICODE_STRING from a C# string. You can see that in the helper code section below. What I have up to and including the call to LsaEnumerateAccountRights() seems to work just fine. Sensible values are returned for the array pointer and for the count. I am at a loss as to how to get at those blasted strings. Help please? Pretty please? UPDATE: nobugz's helper function in his

What does “Invalid managed/unmanaged type combination.” mean?

主宰稳场 提交于 2019-12-29 08:41:17
问题 I have the following struct: [StructLayout(LayoutKind.Auto,Pack=0)] private unsafe struct BIRDSYSTEMCONFIG { public byte bySystemStatus; public byte byError; public byte byNumDevices; public byte byNumServers; public byte byXmtrNum; public ushort wXtalSpeed; public double dMeasurementRate; public byte byChassisNum; public byte byNumChassisDevices; public byte byFirstDeviceNum; public ushort wSoftwareRev; public fixed byte byFlockStatus[127]; } Based on the C++ struct: typedef struct

JAXB Marshaller indentation

被刻印的时光 ゝ 提交于 2019-12-29 07:50:10
问题 I'm using JAXB marshaller to create and format my .xml file. It works pretty well, except one place. The indentation lacks in two places: <Elem1> <Elem2> <Elem3 ID="Elem3.INFO"> <Elem4>INFO</Elem4> </Elem3> <Elem2> <Elem3 ID="Elem3.TEMPLATE"> <Elem4>TEMPLATE</Elem4> </Elem3> </Elem2> <Elem2> <Elem3 ID="Elem3.LEVEL"> <Elem4>LEVEL</Elem4> </Elem3> </Elem2> </Elem2> </Elem1> The rest of the .xml file looks good. I'm using this method to prettify whole code: marshaller.setProperty(Marshaller.JAXB

Marshal an array of strings from C# to C code using p/invoke

左心房为你撑大大i 提交于 2019-12-29 01:23:57
问题 I need to pass an array of C# strings into C code Example C code void print_string_array(const char** str_array, int length){ for (int i = 0; i < length; ++i) { printf("Sting[%l] = %s\n", i, str_array[i]); } } C# that I have tried (This did not work) string foo[] = {"testing", "one", "two", "three"}; print_string_array(foo, foo.Length); [DllImport(my_C_dll, CharSet = CharSet.Ansi)] private static extern void print_string_array([In][MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType

C# Marshalling a C++ struct with wchar_t* member occasionally leaves the heap corrupted

一世执手 提交于 2019-12-26 06:04:22
问题 I have declared a struct as follows: // C++ struct TestStruct { wchar_t* TestString; }; and the corresponding managed representation // C# [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct TestStruct { [MarshalAs(UnmanagedType.LPWStr)] public string TestString; } As well as this function: // C++ __declspec(dllexport) void __stdcall FillMultipleStructs(TestStruct* testStructures, const short arrayLength) { for(int i = 0; i < arrayLength; i++) { const wchar_t

C# Marshalling a C++ struct with wchar_t* member occasionally leaves the heap corrupted

六月ゝ 毕业季﹏ 提交于 2019-12-26 06:04:01
问题 I have declared a struct as follows: // C++ struct TestStruct { wchar_t* TestString; }; and the corresponding managed representation // C# [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct TestStruct { [MarshalAs(UnmanagedType.LPWStr)] public string TestString; } As well as this function: // C++ __declspec(dllexport) void __stdcall FillMultipleStructs(TestStruct* testStructures, const short arrayLength) { for(int i = 0; i < arrayLength; i++) { const wchar_t

C# Marshalling a C++ struct with wchar_t* member occasionally leaves the heap corrupted

落爺英雄遲暮 提交于 2019-12-26 06:02:07
问题 I have declared a struct as follows: // C++ struct TestStruct { wchar_t* TestString; }; and the corresponding managed representation // C# [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct TestStruct { [MarshalAs(UnmanagedType.LPWStr)] public string TestString; } As well as this function: // C++ __declspec(dllexport) void __stdcall FillMultipleStructs(TestStruct* testStructures, const short arrayLength) { for(int i = 0; i < arrayLength; i++) { const wchar_t

Marshalling nested struct between C# and C - Simple HelloWorld

ⅰ亾dé卋堺 提交于 2019-12-25 16:47:50
问题 I am running into an issue where data from the parent struct is correctly marshalled, but the data in the child struct is not. The struct definitions and functions in C: struct contact_info { char cell[32]; char home[32]; }; struct human { char first[32]; char last[32]; struct contact_info *contact; }; __declspec(dllexport) int __cdecl say_hello(struct human *person); __declspec(dllexport) int __cdecl import_csv(char *csvPath, struct human *person); The C# P/Invoke code: [StructLayout