You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question, could you please tell me whether twain can be used by console programs to call scanner? Because of some special operations, I need to export it into dll for nodejs to call. However, the current problem is that all demo is based on mfc project, but the console program cannot simulate callback notification, that is to say, After I called the scanner, I couldn't listen for the callback event, so I couldn't get the image information, attached my code and some clues from the documentation
void CTwain::startScan(const char* sourceName) {
TW_IDENTITY source = getSourceByName(sourceName);
if (source.Id == 0 && source.Version.MajorNum == 0 && source.Version.MinorNum == 0) {
return;
}
if (OpenSource(&source))
{
BOOL ret_value = SetCapability(CAP_DUPLEXENABLED, 0, TRUE);
ret_value = SetCapability(ICAP_SUPPORTEDSIZES, 0, TRUE);
ret_value = SetCapability(ICAP_PIXELTYPE, 0, TRUE);
ret_value = SetResolution(ICAP_XRESOLUTION, 0);
ret_value = SetResolution(ICAP_YRESOLUTION, 300);
//SetImageCount(-1)
EnableSource(true);
//注册回调事件
if (SourceEnabled())
{
MSG windowsMsg;
windowsMsg.message = WM_USER; // 模拟的消息类型
windowsMsg.wParam = 0; // 模拟的消息参数
windowsMsg.lParam = 0; // 模拟的消息参数
windowsMsg.hwnd = m_hMessageWnd;
TW_EVENT twEvent;
twEvent.pEvent = &m_hMessageWnd;
twEvent.TWMessage = MSG_XFERREADY;
HWND han = GetConsoleWindow();
bool result = IsDialogMessage(han, (LPMSG)(twEvent.pEvent));
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(1));
CallTwainProc(&m_AppId, &m_Source, DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, &twEvent);
TranslateMessage(twEvent);
}
}
}
}
The following is the content of your source code, and I have questions
if (hImageDlg && IsDialogMessage(hImageDlg,
(LPMSG)(((pTW_EVENT)pData)->pEvent)))
{
twRc = TWRC_DSEVENT;
// The source should, for proper form, return a MSG_NULL
// for all Windows messages processed by the Data Source
((pTW_EVENT)pData)->TWMessage = MSG_NULL;
}
else
{
// notify the application that the source did not
// consume this message
TWAIN 2.3 Specification 12-7
twRc = TWRC_NOTDSEVENT;
((pTW_EVENT)pData)->TWMessage = MSG_NULL;
}
The text was updated successfully, but these errors were encountered:
I have a question, could you please tell me whether twain can be used by console programs to call scanner? Because of some special operations, I need to export it into dll for nodejs to call. However, the current problem is that all demo is based on mfc project, but the console program cannot simulate callback notification, that is to say, After I called the scanner, I couldn't listen for the callback event, so I couldn't get the image information, attached my code and some clues from the documentation
void CTwain::startScan(const char* sourceName) {
TW_IDENTITY source = getSourceByName(sourceName);
if (source.Id == 0 && source.Version.MajorNum == 0 && source.Version.MinorNum == 0) {
return;
}
if (OpenSource(&source))
{
BOOL ret_value = SetCapability(CAP_DUPLEXENABLED, 0, TRUE);
ret_value = SetCapability(ICAP_SUPPORTEDSIZES, 0, TRUE);
ret_value = SetCapability(ICAP_PIXELTYPE, 0, TRUE);
ret_value = SetResolution(ICAP_XRESOLUTION, 0);
ret_value = SetResolution(ICAP_YRESOLUTION, 300);
//SetImageCount(-1)
EnableSource(true);
//注册回调事件
if (SourceEnabled())
{
MSG windowsMsg;
windowsMsg.message = WM_USER; // 模拟的消息类型
windowsMsg.wParam = 0; // 模拟的消息参数
windowsMsg.lParam = 0; // 模拟的消息参数
windowsMsg.hwnd = m_hMessageWnd;
TW_EVENT twEvent;
twEvent.pEvent = &m_hMessageWnd;
twEvent.TWMessage = MSG_XFERREADY;
HWND han = GetConsoleWindow();
bool result = IsDialogMessage(han, (LPMSG)(twEvent.pEvent));
while (true) {
std::this_thread::sleep_for(std::chrono::seconds(1));
CallTwainProc(&m_AppId, &m_Source, DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, &twEvent);
TranslateMessage(twEvent);
}
}
}
}
The following is the content of your source code, and I have questions
if (hImageDlg && IsDialogMessage(hImageDlg,
(LPMSG)(((pTW_EVENT)pData)->pEvent)))
{
twRc = TWRC_DSEVENT;
// The source should, for proper form, return a MSG_NULL
// for all Windows messages processed by the Data Source
((pTW_EVENT)pData)->TWMessage = MSG_NULL;
}
else
{
// notify the application that the source did not
// consume this message
TWAIN 2.3 Specification 12-7
twRc = TWRC_NOTDSEVENT;
((pTW_EVENT)pData)->TWMessage = MSG_NULL;
}
The text was updated successfully, but these errors were encountered: