|
using System;
using System.Runtime.InteropServices;
using System.Text;
/*****************************************************************************************
* Copyright (c) 2006 T. ALmdal
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
/*******************************************************************************************/
namespace Almdal.AutoPlayListener {
/// <summary>
/// Pointer to a Shell ITEMIDLIST structure, which s used to identify objects in the Shell namespace
/// </summary>
public class PIdl : IDisposable {
public IntPtr _pidl;
public PIdl() { _pidl = IntPtr.Zero; }
public PIdl(IntPtr pidl) { _pidl = pidl; }
public void Dispose() {
if (!IntPtr.Zero.Equals(_pidl)) { // only release the storage if the pointer is valid
IMalloc malloc = null;
WinApi.SHGetMalloc(out malloc);
try {
malloc.Free((IntPtr)_pidl);
} finally {
Marshal.ReleaseComObject(malloc);
}
}
}
public static IntPtr NextPIDL(IntPtr ptr) {
if (!IntPtr.Zero.Equals(ptr)) {
short cb = Marshal.ReadInt16(ptr);
return new IntPtr((int)ptr + cb);
// must have 'int' here
// it changes the IntPtr myIntPtr
// to 'int', a memory address
}
else {
return ptr;
}
}
public int Count {
get {
int Result = 0;
IntPtr IDList = _pidl;
if (IDList != IntPtr.Zero) {
short cb = Marshal.ReadInt16(IDList);
while (cb != 0) {
Result++;
IDList = NextPIDL(IDList);
cb = Marshal.ReadInt16(IDList);
}
}
return Result;
}
}
public bool isNull() { return IntPtr.Zero.Equals(_pidl); }
public static explicit operator IntPtr(PIdl p) { return p._pidl; }
public static explicit operator PIdl(IntPtr p) { return new PIdl(p); }
public IntPtr Detach() {
IntPtr pidl = _pidl;
_pidl = IntPtr.Zero;
return pidl;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.