Fixed some comments and types.

This commit is contained in:
soukoku
2014-04-04 22:19:16 -04:00
parent c7ca66836b
commit 4fa3e77fba
37 changed files with 354 additions and 69 deletions

View File

@@ -9,8 +9,10 @@ namespace NTwain
{
/// <summary>
/// Provides methods for managing memory on data exchanged with twain sources.
/// This should only be used after the DSM has been opened in <see cref="TwainSession"/>
/// via <see cref="TwainSession.OpenManager"/>.
/// </summary>
class MemoryManager
public class MemoryManager
{
/// <summary>
/// Gets the global <see cref="MemoryManager"/> instance.
@@ -30,6 +32,11 @@ namespace NTwain
TWEntryPoint _twain2Entry;
/// <summary>
/// Function to allocate memory. Calls to this must be coupled with <see cref="MemFree"/> later.
/// </summary>
/// <param name="size">The size in bytes.</param>
/// <returns>Handle to the allocated memory.</returns>
public IntPtr MemAllocate(uint size)
{
if (_twain2Entry != null && _twain2Entry.AllocateFunction != null)
@@ -42,6 +49,11 @@ namespace NTwain
return GlobalAlloc(0x0040, new UIntPtr(size));
}
}
/// <summary>
/// Function to free memory.
/// </summary>
/// <param name="handle">The handle from <see cref="MemAllocate"/>.</param>
public void MemFree(IntPtr handle)
{
if (_twain2Entry != null && _twain2Entry.FreeFunction != null)
@@ -53,6 +65,12 @@ namespace NTwain
GlobalFree(handle);
}
}
/// <summary>
/// Function to lock some memory. Calls to this must be coupled with <see cref="MemUnlock"/> later.
/// </summary>
/// <param name="handle">The handle to allocated memory.</param>
/// <returns>Handle to the lock.</returns>
public IntPtr MemLock(IntPtr handle)
{
if (_twain2Entry != null && _twain2Entry.LockFunction != null)
@@ -64,6 +82,11 @@ namespace NTwain
return GlobalLock(handle);
}
}
/// <summary>
/// Function to unlock a previously locked memory region.
/// </summary>
/// <param name="handle">The handle from <see cref="MemLock"/>.</param>
public void MemUnlock(IntPtr handle)
{
if (_twain2Entry != null && _twain2Entry.UnlockFunction != null)
@@ -82,14 +105,14 @@ namespace NTwain
static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes);
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
public static extern IntPtr GlobalFree(IntPtr hMem);
static extern IntPtr GlobalFree(IntPtr hMem);
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
public static extern IntPtr GlobalLock(IntPtr handle);
static extern IntPtr GlobalLock(IntPtr handle);
[DllImport("kernel32", SetLastError = true, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GlobalUnlock(IntPtr handle);
static extern bool GlobalUnlock(IntPtr handle);
#endregion
}