Added a DeletedIconOverlay.cs
[pithos-ms-client] / trunk / Pithos.ShellExtensions / MarshalHelpers.cs
1 using System;
2 using System.Diagnostics.Contracts;
3 using System.Runtime.InteropServices;
4 using System.Text;
5
6 namespace Pithos.ShellExtensions
7 {
8     public static class MarshalHelpers
9     {
10         
11         public static void CopyToBuffer(string input, IntPtr buffer, int bufferSize)
12         {        
13             Contract.Requires(buffer != IntPtr.Zero);
14             Contract.Requires(bufferSize >=0 );
15             
16             var bytes = Encoding.Unicode.GetBytes(input);
17             
18             if (bytes.Length + 2 >= bufferSize) 
19                 return;
20
21             for (var i = 0; i < bytes.Length; i++)
22             {
23                 Marshal.WriteByte(buffer, i, bytes[i]);
24             }
25             //write the null terminator "\0\0" 
26             Marshal.WriteByte(buffer, bytes.Length, 0);
27             Marshal.WriteByte(buffer, bytes.Length + 1, 0);
28         }
29     }
30 }