2014-04-20 16:57:38 -04:00
|
|
|
|
using NTwain.Data;
|
|
|
|
|
using System;
|
2014-04-20 18:42:51 -04:00
|
|
|
|
using System.ComponentModel;
|
2014-04-20 16:57:38 -04:00
|
|
|
|
|
2014-09-17 20:15:05 -04:00
|
|
|
|
namespace NTwain.Internals
|
2014-04-20 16:57:38 -04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides methods for managing memory on data exchanged with twain sources using old win32 methods.
|
|
|
|
|
/// </summary>
|
|
|
|
|
class WinMemoryManager : IMemoryManager
|
|
|
|
|
{
|
|
|
|
|
public IntPtr Allocate(uint size)
|
|
|
|
|
{
|
2014-04-20 22:24:05 -04:00
|
|
|
|
IntPtr retVal = UnsafeNativeMethods.WinGlobalAlloc(0x0040, new UIntPtr(size));
|
2014-04-20 16:57:38 -04:00
|
|
|
|
|
|
|
|
|
if (retVal == IntPtr.Zero)
|
|
|
|
|
{
|
2014-04-20 18:42:51 -04:00
|
|
|
|
throw new Win32Exception();
|
2014-04-20 16:57:38 -04:00
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Free(IntPtr handle)
|
|
|
|
|
{
|
2014-04-20 22:24:05 -04:00
|
|
|
|
UnsafeNativeMethods.WinGlobalFree(handle);
|
2014-04-20 16:57:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IntPtr Lock(IntPtr handle)
|
|
|
|
|
{
|
2014-04-20 22:24:05 -04:00
|
|
|
|
return UnsafeNativeMethods.WinGlobalLock(handle);
|
2014-04-20 16:57:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unlock(IntPtr handle)
|
|
|
|
|
{
|
2014-04-20 22:24:05 -04:00
|
|
|
|
UnsafeNativeMethods.WinGlobalUnlock(handle);
|
2014-04-20 16:57:38 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|