twaindotnet - Setting default TWAIN data source without using API UI menu -
using twaindotnet library in c#, i'm wondering if there's way set default datasource using library.
as feeble attempt, i've tried adding setdefault method datasource class of twaindonet, this
public static void setdefault(identity applicationid, iwindowsmessagehook messagehook, datasource newdatasource) { var defaultsourceid = newdatasource.sourceid; // attempt information 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 default source: " + result, result, status); } } which called datasourcemanage class this
public void selectsource(datasource datasource) { datasource.dispose(); datasource.setdefault(applicationid, _messagehook, datasource); } but when try use setdefault, twain32native.dsmidentity results in failure being returned.
i copied setdefault setdefaultdatasource method twain sample data source , application
ptw_identity twainapp::setdefaultdatasource(unsigned int _index) { if(m_dsmstate < 3) { cout << "you need open dsm first." << endl; return null; } else if(m_dsmstate > 3) { printcmdmessage("a source has been opened, please close first\n"); return null; } if(_index >= 0 && _index < m_datasources.size()) { m_pdatasource = &(m_datasources[_index]); // set 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 data source info!"); break; } } else { return null; } return m_pdatasource; } any appreciated.
the possible cause version of twain dsm low. dsm 2.0 or above supports setting default twain data source.
Comments
Post a Comment