ntwain
ntwain copied to clipboard
[BUG] CreateDirectory() errorCode == 183
Tried to build simple application
` public class ScannerDevice { private const string DEFAULT_SOURCE = "CS 2553ci";
private readonly TwainSession twain;
private readonly ILogger<ScannerDevice> logger; // declare a logger
public ScannerDevice(ILogger<ScannerDevice> logger) // inject logger via constructor
{
this.logger = logger;
twain = InitTwain();
}
private TwainSession InitTwain()
{
var twain = new TwainSession(TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetExecutingAssembly()));
twain.TransferReady += (s, e) => { logger.LogInformation("Transfer ready on thread {0}.", Thread.CurrentThread.ManagedThreadId); };
twain.DataTransferred += (s, e) =>
{
if (e.NativeData != IntPtr.Zero)
{
logger.LogInformation("SUCCESS! Got twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
else
{
logger.LogWarning("BUMMER! No twain data on thread {0}.", Thread.CurrentThread.ManagedThreadId);
}
};
twain.SourceDisabled += (s, e) =>
{
logger.LogInformation("Source disabled on thread {0}.", Thread.CurrentThread.ManagedThreadId);
var rc = twain.CurrentSource.Close();
rc = twain.Close();
};
logger.LogInformation("Twain initialized");
return twain;
}
public void Scan()
{
logger.LogInformation("Getting ready to do twain stuff on thread {0}...", Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(1000);
try
{
var rc = twain.Open();
logger.LogInformation("Twain open");
foreach (var s in twain)
{
logger.LogInformation("Twain source detected: {}", s.Name);
}
if (rc == ReturnCode.Success)
{
var hit = twain.FirstOrDefault(s => string.Equals(s.Name, DEFAULT_SOURCE));
if (hit == null)
{
logger.LogWarning("The default source \"" + DEFAULT_SOURCE + "\" is not installed.");
twain.Close();
}
else
{
logger.LogInformation("Opening {}", DEFAULT_SOURCE);
rc = hit.Open();
logger.LogInformation("Opened {}", DEFAULT_SOURCE);
if (rc == ReturnCode.Success)
{
logger.LogInformation("Starting capture from the default source...");
rc = hit.Enable(SourceEnableMode.NoUI, false, IntPtr.Zero);
}
else
{
twain.Close();
}
}
}
else
{
logger.LogError("Failed to open dsm with rc={0}!", rc);
}
}
catch (Exception ex)
{
logger.LogError("{}", ex);
}
}
} `
When I call it using
var scanner = new ScannerDevice(logger); scanner.Scan();
I get an error CreateDirectory() errorCode == 183
The lib does not have code that creates directories. Could it be the scanner driver is trying to use some temp folder and don't have permissions?
I apologize, it looks like your assumption is correct. But I have absolutely no clue what kyocera CS 2553ci tries to create and how to bypass that...