-
Notifications
You must be signed in to change notification settings - Fork 0
/
Marchal.cs
54 lines (44 loc) · 1.89 KB
/
Marchal.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// using System;
// using System.Text;
// using System.Runtime.InteropServices;
// public struct Point
// {
// public Int32 x, y;
// }
// public sealed class App
// {
// static void Main()
// {
// // Demonstrate the use of public static fields of the Marshal class.
// Console.WriteLine("SystemDefaultCharSize={0}, SystemMaxDBCSCharSize={1}",
// Marshal.SystemDefaultCharSize, Marshal.SystemMaxDBCSCharSize);
// // Demonstrate the use of the SizeOf method of the Marshal class.
// Console.WriteLine("Number of bytes needed by a Point object: {0}",
// Marshal.SizeOf(typeof(Point)));
// Point p = new Point();
// Console.WriteLine("Number of bytes needed by a Point object: {0}",
// Marshal.SizeOf(p));
// // Demonstrate how to call GlobalAlloc and
// // GlobalFree using the Marshal class.
// IntPtr hglobal = Marshal.AllocHGlobal(100);
// Marshal.FreeHGlobal(hglobal);
// // Demonstrate how to use the Marshal class to get the Win32 error
// // code when a Win32 method fails.
// Boolean f = CloseHandle(new IntPtr(-1));
// if (!f)
// {
// Console.WriteLine("CloseHandle call failed with an error code of: {0}",
// Marshal.GetLastWin32Error());
// }
// }
// // This is a platform invoke prototype. SetLastError is true, which allows
// // the GetLastWin32Error method of the Marshal class to work correctly.
// [DllImport("Kernel32", ExactSpelling = true, SetLastError = true)]
// static extern Boolean CloseHandle(IntPtr h);
// }
// // This code produces the following output.
// //
// // SystemDefaultCharSize=2, SystemMaxDBCSCharSize=1
// // Number of bytes needed by a Point object: 8
// // Number of bytes needed by a Point object: 8
// // CloseHandle call failed with an error code of: 6