Fixed some warnings.

This commit is contained in:
Eugene Wang 2023-04-07 22:20:42 -04:00
parent 6fff04fc65
commit 54c7fc1d50
4 changed files with 12 additions and 6 deletions

View File

@ -181,10 +181,11 @@ namespace WinFormSample
// there may be a better way...
private string ReadTypedValue(CAP cap, TWTY type, bool forCurrent)
{
STS sts = default;
switch (type)
{
case TWTY.UINT8:
var sts = forCurrent ?
sts = forCurrent ?
twain.GetCapCurrent(cap, out byte ubval) :
twain.GetCapDefault(cap, out ubval);
return ubval.ToString();
@ -251,6 +252,7 @@ namespace WinFormSample
case TWTY.HANDLE:
break;
}
Debug.WriteLine($"{nameof(ReadTypedValue)}({cap}, {type}, {forCurrent}) => {sts}");
return "";
}

View File

@ -292,7 +292,7 @@ namespace NTwain.Data
//}
// Set the Item...
WriteRangeValues(memMgr, lockedPtr, itemType, value);
WriteRangeValues(lockedPtr, itemType, value);
}
finally
{
@ -301,7 +301,7 @@ namespace NTwain.Data
return twCap;
}
static void WriteRangeValues<TValue>(IMemoryManager memMgr, IntPtr lockedPtr, TWTY itemType, Range<TValue> value) where TValue : struct
static void WriteRangeValues<TValue>(IntPtr lockedPtr, TWTY itemType, Range<TValue> value) where TValue : struct
{
// TODO: reduce this later

View File

@ -26,7 +26,7 @@ namespace NTwain.Native
public static unsafe byte[]? GetBitmapData(System.Buffers.ArrayPool<byte> xferMemPool, IntPtr data)
{
var infoHeader = (BITMAPINFOHEADER)Marshal.PtrToStructure(data, typeof(BITMAPINFOHEADER));
var infoHeader = Marshal.PtrToStructure<BITMAPINFOHEADER>(data);
if (infoHeader.Validate())
{
var fileHeaderSize = Marshal.SizeOf(typeof(BITMAPFILEHEADER));
@ -75,7 +75,7 @@ namespace NTwain.Native
for (int i = 0; i < 999; i++)
{
tagPtr += (tagSize * i);
var tag = (TIFFTAG)Marshal.PtrToStructure((IntPtr)tagPtr, typeof(TIFFTAG));
var tag = Marshal.PtrToStructure<TIFFTAG>((IntPtr)tagPtr);
switch (tag.u16Tag)
{

View File

@ -98,7 +98,9 @@ namespace NTwain
internal IntPtr _hwnd;
internal TW_USERINTERFACE _userInterface; // kept around for disable to use
#if WINDOWS || NETFRAMEWORK
TW_EVENT _procEvent; // kept here so the alloc/free only happens once
#endif
// test threads a bit
readonly BlockingCollection<MSG> _bgPendingMsgs = new();
private readonly IThreadMarshaller _uiThreadMarshaller;
@ -165,7 +167,9 @@ namespace NTwain
// this will end the bg thread
_bgPendingMsgs.CompleteAdding();
}
#if WINDOWS || NETFRAMEWORK
if (_procEvent.pEvent != IntPtr.Zero) Marshal.FreeHGlobal(_procEvent.pEvent);
#endif
disposedValue = true;
}
}
@ -249,7 +253,7 @@ namespace NTwain
protected STS WrapInSTS(TWRC rc, bool dsmOnly = false)
{
if (rc != TWRC.FAILURE) return new STS { RC = rc };
var sts = new STS { RC = rc, STATUS = GetLastStatus() };
var sts = new STS { RC = rc, STATUS = GetLastStatus(dsmOnly) };
if (sts.STATUS.ConditionCode == TWCC.BADDEST)
{
// TODO: the current ds is bad, should assume we're back in S3?