首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用API UI菜单设置默认TWAIN数据源

不使用API UI菜单设置默认TWAIN数据源
EN

Stack Overflow用户
提问于 2013-05-15 10:45:22
回答 1查看 3.1K关注 0票数 0

使用C#中的twaindotnet库,我想知道是否有一种方法可以使用该库来设置默认数据源。

作为一次失败的尝试,我尝试向twaindonetDataSource类添加一个SetDefault方法,如下所示

代码语言:javascript
复制
    public static void SetDefault(Identity applicationId, IWindowsMessageHook messageHook, DataSource newDataSource)
    {
        var defaultSourceId = newDataSource.SourceId;

        // Attempt to get information about the system default source
        var result = Twain32Native.DsmIdentity(
            applicationId,
            IntPtr.Zero,
            DataGroup.Control,
            DataArgumentType.Identity,
            Message.Set,
            defaultSourceId);

        if (result != TwainResult.Success)
        {
            var status = DataSourceManager.GetConditionCode(applicationId, null);
            throw new TwainException("Error getting information about the default source: " + result, result, status);
        }
    }

它从DataSourceManage类中调用,如下所示

代码语言:javascript
复制
    public void SelectSource(DataSource dataSource)
    {
        DataSource.Dispose();
        DataSource.SetDefault(ApplicationId, _messageHook, dataSource);
    }

但是当我尝试使用SetDefault时,Twain32Native.DsmIdentity总是导致返回Failure

我基本上是从SetDefault复制了来自TWAIN sample Data Source and ApplicationsetDefaultDataSource方法

代码语言:javascript
复制
pTW_IDENTITY TwainApp::setDefaultDataSource(unsigned int _index)
{
if(m_DSMState < 3)
{
    cout << "You need to open the DSM first." << endl;
    return NULL;
}

else if(m_DSMState > 3)
{
    PrintCMDMessage("A source has already been opened, please close it first\n");
    return NULL;
}

if(_index >= 0 && _index < m_DataSources.size())
{
    m_pDataSource = &(m_DataSources[_index]);

    // set the specific data source
    TW_UINT16 twrc;
    twrc = _DSM_Entry(
        &m_MyInfo,
        0,
        DG_CONTROL,
        DAT_IDENTITY,
        MSG_SET,
        (TW_MEMREF) m_pDataSource);

    switch (twrc)
    {
    case TWRC_SUCCESS:
        break;

    case TWRC_FAILURE:
        printError(0, "Failed to get the data source info!");
        break;
    }
}
else
{
    return NULL;
}

return m_pDataSource;
}

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-15 15:08:30

可能的原因是您的TWAIN DSM版本太低。仅DSM 2.0或更高版本支持设置默认TWAIN数据源。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16555951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档