Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c++ console program how to implement scanning #26

Open
yewanji opened this issue May 23, 2023 · 0 comments
Open

c++ console program how to implement scanning #26

yewanji opened this issue May 23, 2023 · 0 comments

Comments

@yewanji
Copy link

yewanji commented May 23, 2023

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant