diff --git a/.openpublishing.publish.config.json b/.openpublishing.publish.config.json index aa4079b84a5..97fe70dd6b1 100644 --- a/.openpublishing.publish.config.json +++ b/.openpublishing.publish.config.json @@ -5,7 +5,9 @@ "build_source_folder": ".", "build_output_subfolder": ".", "locale": "en-us", - "xref_query_tags": ["/uwp/api"], + "xref_query_tags": [ + "/uwp/api" + ], "monikers": [], "moniker_ranges": [], "open_to_public_contributors": true, @@ -90,5 +92,8 @@ "target_framework": "net45", "version": "latest" } - ] + ], + "docs_build_engine": { + "name": "docfx_v3" + } } diff --git a/samples/snippets/csharp/VS_Snippets_CLR/PtrToStructure/CS/pts.cs b/samples/snippets/csharp/VS_Snippets_CLR/PtrToStructure/CS/pts.cs index bc90f057759..defd6eeae54 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/PtrToStructure/CS/pts.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/PtrToStructure/CS/pts.cs @@ -1,47 +1,90 @@ -using System; +using System; + using System.Runtime.InteropServices; -namespace Testing -{ - class Class1 +namespace Testing + +{ + + class Class1 + { - // - [StructLayout(LayoutKind.Sequential)] - public class INNER - { - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + // + + [StructLayout(LayoutKind.Sequential)] + + public class INNER + + { + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + public string field1 = "Test"; - } - [StructLayout(LayoutKind.Sequential)] - public struct OUTER - { - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] - public string field1; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)] - public byte[] inner; } - [DllImport(@"SomeTestDLL.dll")] + } + + [StructLayout(LayoutKind.Sequential)] + + public struct OUTER + + { + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + + public string field1; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)] + + public byte[] inner; + } + [DllImport(@"SomeTestDLL.dll")] + public static extern void CallTest( ref OUTER po); - static void Main(string[] args) - { - OUTER ed = new OUTER(); - INNER[] inn=new INNER[10]; - INNER test = new INNER(); + static void Main(string[] args) + + { + + OUTER ed = new OUTER(); + + INNER[] inn=new INNER[10]; + + INNER test = new INNER(); + int iStructSize = Marshal.SizeOf(test); - int sz =inn.Length * iStructSize; + int sz =inn.Length * iStructSize; + ed.inner = new byte[sz]; - try - { - CallTest( ref ed); } - catch(Exception e) - { - Console.WriteLine(e.Message); } - IntPtr buffer = Marshal.AllocCoTaskMem(iStructSize*10); + try + + { + + CallTest( ref ed); + } + + catch(Exception e) + + { + + Console.WriteLine(e.Message); + } + + IntPtr buffer = Marshal.AllocCoTaskMem(iStructSize*10); + Marshal.Copy(ed.inner,0,buffer,iStructSize*10); - int iCurOffset = 0; - for(int i=0;i<10;i++) + int iCurOffset = 0; + + for(int i=0;i<10;i++) + { inn[i] = (INNER)Marshal.PtrToStructure(new -IntPtr(buffer.ToInt32()+iCurOffset),typeof(INNER) ); - iCurOffset += iStructSize; } - Console.WriteLine(ed.field1); - Marshal.FreeCoTaskMem(buffer); } - // } } +IntPtr(buffer.ToInt32()+iCurOffset),typeof(INNER) ); + + iCurOffset += iStructSize; + } + + Console.WriteLine(ed.field1); + + Marshal.FreeCoTaskMem(buffer); + } + // + } +} +