Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .openpublishing.publish.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -90,5 +92,8 @@
"target_framework": "net45",
"version": "latest"
}
]
],
"docs_build_engine": {
"name": "docfx_v3"
}
}
119 changes: 81 additions & 38 deletions samples/snippets/csharp/VS_Snippets_CLR/PtrToStructure/CS/pts.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,90 @@
using System;
using System;

using System.Runtime.InteropServices;
namespace Testing
{
class Class1
namespace Testing

{

class Class1

{
// <snippet1>
[StructLayout(LayoutKind.Sequential)]
public class INNER
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
// <snippet1>

[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); }
// </snippet1> }}
IntPtr(buffer.ToInt32()+iCurOffset),typeof(INNER) );

iCurOffset += iStructSize;
}

Console.WriteLine(ed.field1);

Marshal.FreeCoTaskMem(buffer);
}
// </snippet1>
}
}