Blog sur les technos .net
Puisque ces mystères me dépassent, feignons d'en être l'organisateur.

How to get twain capabilites in using MSG_GET

By TheGrandBlack
private bool InitApplication()
{
CloseDataSource();
if (m_applicationId.Id == IntPtr.Zero)
{
Init(m_hwnd);
if (m_applicationId.Id == IntPtr.Zero)
return false;
}
return true;
}

public object GetCapability(TwCap p_capabilityValue)
{
if (!InitApplication())
return null;
TwainRC v_rc = TwainInterop.DSMident(m_applicationId,
IntPtr.Zero,
TwainDG.Control, TwDAT.Identity,
TwainMSG.OpenDS,
m_dataSource);

if (v_rc != TwainRC.Success)
return null;

using (TwainCapability v_cap = new TwainCapability(p_capabilityValue))
{
v_cap.m_conType = (ushort)TwOn.DontCare16;
v_cap.m_handle = IntPtr.Zero;
try
{
v_rc = TwainInterop.DScap(
m_applicationId,
m_dataSource,
TwainDG.Control,
TwDAT.Capability,
TwainMSG.MSG_GET,
v_cap);

if (v_rc == TwainRC.Success)
{
if (v_cap.m_handle != IntPtr.Zero)
{
IntPtr v_pv = WinInterop.GlobalLock(v_cap.m_handle);
try
{
switch (v_cap.m_conType)
{
case (ushort)TwOn.Enumeration:
TwEnumeration v_enum =
(TwEnumeration)Marshal.PtrToStructure(v_pv, typeof(TwEnumeration));
return v_enum;
case (ushort)TwOn.Range:
TwRange v_range =
(TwRange)Marshal.PtrToStructure(v_pv, typeof(TwRange));
return v_range;
case (ushort)TwOn.One:
TwOneValue v_one =
(TwOneValue)Marshal.PtrToStructure(v_pv, typeof(TwOneValue));
return v_one;
case (ushort)TwOn.Array:
TwArray v_array =
(TwArray)Marshal.PtrToStructure(v_pv, typeof(TwArray));
return v_array;
default:
break;
}
}
finally
{
WinInterop.GlobalUnlock(v_cap.m_handle);
WinInterop.GlobalFree(v_cap.m_handle);
}
}
}
}
finally
{
CloseDataSource();
}
return null;
}
}
 

0 comments so far.

Something to say?