From b40a505456b206c019a1351698339caba644fa2d Mon Sep 17 00:00:00 2001 From: VSC-Service-Account Date: Thu, 30 Jul 2020 07:14:18 +0000 Subject: [PATCH 1/2] Update config to enable docfx v3 --- .openpublishing.publish.config.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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" + } } From 80ac8b939afebabb4c1fb631e3121c24d2ec78a3 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 31 Jul 2020 11:46:28 +0800 Subject: [PATCH 2/2] Update pts.cs --- .../VS_Snippets_CLR/PtrToStructure/CS/pts.cs | 119 ++++++++++++------ 1 file changed, 81 insertions(+), 38 deletions(-) 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); + } + // + } +} +