Game Development Reference
In-Depth Information
Implementation
The code to implement this feature is very simple. The solution involves a few
P\Invoke calls, so the first logical step is to include the appropriate namespace.
using System.Runtime.InteropServices;
The API signatures we will invoke are described in the following code. The first
signature is sent the pointer type, along with a pointer to the actual data. The sec-
ond signature is nearly identical to the first, except a string is passed into it instead
of a pointer.
[DllImport(“shell32.dll”)]
internal static extern void SHAddToRecentDocs(UInt32 pointerType, IntPtr pointer);
[DllImport(“shell32.dll”)]
internal static extern void SHAddToRecentDocs(UInt32 pointerType,
[MarshalAs(UnmanagedType.LPWStr)] string pointer);
There are three flavors of the SHAddToRecentDocs method that can be used, specified
by the PointerType enumeration. These pointer types are defined in the following
code, and are described in Table 33.1.
internal enum PointerType
{
SHARD_PIDL = 0x00000001,
SHARD_PATHA = 0x00000002,
SHARD_PATHW = 0x00000003,
}
TABLE 33.1 SHAddToRecentDocs Pointer Types
Pointer Type
Description
SHARD_PIDL
Pointer to a PIDL ( ITEMIDLIST structure) identifying the file to add to the
recent documents menu
SHARD_PATHA
Pointer to a null terminated string with the path and filename of the object
SHARD_PATHW
Pointer to a null terminated string with the path and filename of the object;
Unicode formatting
Using the method is very easy. You can either pass in the PIDL of the file if you have
it, or simply specify the system path to the file as a string. Doing so will create a
Search Nedrilad ::




Custom Search