2014-04-21 04:57:38 +08:00
|
|
|
|
using NTwain.Data;
|
|
|
|
|
using NTwain.Internals;
|
|
|
|
|
using System;
|
2014-04-21 06:42:51 +08:00
|
|
|
|
using System.ComponentModel;
|
2014-04-21 04:57:38 +08:00
|
|
|
|
|
|
|
|
|
namespace NTwain
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides methods for managing memory on data exchanged with twain sources using old win32 methods.
|
|
|
|
|
/// This should only be used after the DSM has been opened.
|
|
|
|
|
/// </summary>
|
|
|
|
|
class WinMemoryManager : IMemoryManager
|
|
|
|
|
{
|
|
|
|
|
public IntPtr Allocate(uint size)
|
|
|
|
|
{
|
|
|
|
|
IntPtr retVal = NativeMethods.WinGlobalAlloc(0x0040, new UIntPtr(size));
|
|
|
|
|
|
|
|
|
|
if (retVal == IntPtr.Zero)
|
|
|
|
|
{
|
2014-04-21 06:42:51 +08:00
|
|
|
|
throw new Win32Exception();
|
2014-04-21 04:57:38 +08:00
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Free(IntPtr handle)
|
|
|
|
|
{
|
|
|
|
|
NativeMethods.WinGlobalFree(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IntPtr Lock(IntPtr handle)
|
|
|
|
|
{
|
|
|
|
|
return NativeMethods.WinGlobalLock(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unlock(IntPtr handle)
|
|
|
|
|
{
|
|
|
|
|
NativeMethods.WinGlobalUnlock(handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|