/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/* * twain32shim.exe is a separate 32-bit executable that serves as a shim * between LibreOffice and Windows' 32-bit TWAIN component. Without it, * it's impossible for 64-bit program to use TWAIN on Windows. * Using 64-bit TWAIN DSM library from twain.org to avoid using the shim * is not an option, because scanner manufacturers only provide 32-bit * drivers, and 64-bit drivers are only offered as 3rd-party commercial * products. The shim is also used in 32-bit LibreOffice for uniformity.
*/
if (TWAINState::DSMopened == m_nCurState)
{
ImplOpenSource();
if (TWAINState::DSopened == m_nCurState)
bRet = ImplEnableSource();
}
if (!bRet)
Destroy();
return bRet;
}
void ImpTwain::ImplOpenSourceManager()
{ if (TWAINState::DSMunloaded == m_nCurState)
{
m_hMod = LoadLibraryW(L"TWAIN_32.DLL"); if (!m_hMod)
{ // Windows directory might not be in DLL search path sometimes, so try the full path
sal::systools::CoTaskMemAllocated<wchar_t> sPath; if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Windows, 0, nullptr, &sPath)))
{
std::wstring sPathAndFile(sPath);
sPathAndFile += L"\\TWAIN_32.DLL";
m_hMod = LoadLibraryW(sPathAndFile.c_str());
}
} if (m_hMod)
{
m_nCurState = TWAINState::DSMloaded;
case TWAINState::DSMunloaded:
{ if (nEvent > TWAIN_EVENT_NONE)
NotifyParent(nEvent, reinterpret_cast<LPARAM>(m_hMap));
PostQuitMessage(0);
bFallback = false;
} break;
}
if (bFallback)
ImplFallback(nEvent);
}
void ImpTwain::ImplRequestHdl(WPARAM nRequest)
{ switch (nRequest)
{ case TWAIN_REQUEST_QUIT:
Destroy(); break; case TWAIN_REQUEST_SELECTSOURCE:
NotifyParent(TWAIN_EVENT_REQUESTRESULT, LPARAM(SelectSource())); break; case TWAIN_REQUEST_INITXFER:
NotifyParent(TWAIN_EVENT_REQUESTRESULT, LPARAM(InitXfer())); break;
}
}
} // namespace
int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
{ int argc = 0;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argc != 2) return 1; // Wrong argument count // 1st argument is parent thread handle; must be inherited. // HANDLE is 32-bit in 32-bit applications, so wcstoul is OK.
HANDLE hParentThread = reinterpret_cast<HANDLE>(wcstoul(argv[1], nullptr, 10));
LocalFree(argv); if (!hParentThread) return 2; // Invalid parent thread handle argument value
int nRet = 0; try
{
ImpTwain aImpTwain(hParentThread); // creates main window
MSG msg; while (true)
{
DWORD nWaitResult
= MsgWaitForMultipleObjects(1, &hParentThread, FALSE, INFINITE, QS_ALLINPUT); if (nWaitResult == WAIT_OBJECT_0) return 5; // Parent process' thread died before we exited if (nWaitResult == WAIT_FAILED) return 6; // Some Win32 error // nWaitResult == WAIT_OBJECT_0 + nCount => an event is in queue bool bQuit = false; while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE))
{ // process it here if (msg.message == WM_QUIT)
{
bQuit = true;
nRet = msg.wParam;
} else
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
} if (bQuit) break;
}
} catch (const std::exception& e)
{
printf("Exception thrown: %s", e.what());
nRet = 7;
} return nRet;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.