mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-08 10:34:47 +08:00
Road to v1 begins!
This commit is contained in:
39
NTwain/Internals/WinMemoryManager.cs
Normal file
39
NTwain/Internals/WinMemoryManager.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using NTwain.Data;
|
||||
using NTwain.Internals;
|
||||
using System;
|
||||
|
||||
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)
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user