LibreOffice Module extensions (master) 1
twain32shim.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 */
10
11#pragma once
12
13#include <prewin.h>
14#include <Shlobj.h>
15#include <postwin.h>
16#include <exception>
17#include <string>
18#include <sstream>
19#include <iomanip>
20
21// Don't use WM_USER
22
23// Notifications from shim to parent; wParam = event id
24#define WM_TWAIN_EVENT (WM_USER + 1)
25
26// lParam is HWND
27#define TWAIN_EVENT_NOTIFYHWND 0
28
29// lParam is result (bool indicating success)
30#define TWAIN_EVENT_REQUESTRESULT 1
31
32// lParam is ignored
33#define TWAIN_EVENT_NONE 10
34#define TWAIN_EVENT_QUIT 11
35#define TWAIN_EVENT_SCANNING 12
36
37// lParam is HANDLE to shared file mapping valid in context of parent process
38#define TWAIN_EVENT_XFER 13
39
40// Requests from parent to shim; wParam = request id
41#define WM_TWAIN_REQUEST (WM_USER + 2)
42
43#define TWAIN_REQUEST_QUIT 0 // Destroy()
44#define TWAIN_REQUEST_SELECTSOURCE 1
45#define TWAIN_REQUEST_INITXFER 2
46
47// messages starting from this are not to be used for interprocess communications
48#define WM_SHIM_INTERNAL (WM_USER + 200)
49
50template <typename IntType> std::string Num2Hex(IntType n)
51{
52 std::stringstream sMsg;
53 sMsg << "0x" << std::uppercase << std::setfill('0') << std::setw(sizeof(n) * 2) << std::hex
54 << n;
55 return sMsg.str();
56}
57
58void ThrowWin32Error(const char* sFunc, DWORD nWin32Error)
59{
60 std::stringstream sMsg;
61 sMsg << sFunc << " failed with Win32 error code " << Num2Hex(nWin32Error) << "!";
62
63 throw std::exception(sMsg.str().c_str());
64}
65
66void ThrowLastError(const char* sFunc) { ThrowWin32Error(sFunc, GetLastError()); }
67
68/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int64 n
std::string Num2Hex(IntType n)
Definition: twain32shim.hxx:50
void ThrowLastError(const char *sFunc)
Definition: twain32shim.hxx:66
void ThrowWin32Error(const char *sFunc, DWORD nWin32Error)
Definition: twain32shim.hxx:58