Get the style color and number just once
[LibreOffice.git] / extensions / source / scanner / twain32shim.hxx
blobc9e87ee8bb57336f036d31658a82480b271da790
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 */
11 #pragma once
13 #include <prewin.h>
14 #include <Shlobj.h>
15 #include <postwin.h>
16 #include <exception>
17 #include <string>
18 #include <sstream>
19 #include <iomanip>
21 // Don't use WM_USER
23 // Notifications from shim to parent; wParam = event id
24 #define WM_TWAIN_EVENT (WM_USER + 1)
26 // lParam is HWND
27 #define TWAIN_EVENT_NOTIFYHWND 0
29 // lParam is result (bool indicating success)
30 #define TWAIN_EVENT_REQUESTRESULT 1
32 // lParam is ignored
33 #define TWAIN_EVENT_NONE 10
34 #define TWAIN_EVENT_QUIT 11
35 #define TWAIN_EVENT_SCANNING 12
37 // lParam is HANDLE to shared file mapping valid in context of parent process
38 #define TWAIN_EVENT_XFER 13
40 // Requests from parent to shim; wParam = request id
41 #define WM_TWAIN_REQUEST (WM_USER + 2)
43 #define TWAIN_REQUEST_QUIT 0 // Destroy()
44 #define TWAIN_REQUEST_SELECTSOURCE 1
45 #define TWAIN_REQUEST_INITXFER 2
47 // messages starting from this are not to be used for interprocess communications
48 #define WM_SHIM_INTERNAL (WM_USER + 200)
50 template <typename IntType> std::string Num2Hex(IntType n)
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();
58 void ThrowWin32Error(const char* sFunc, DWORD nWin32Error)
60 std::stringstream sMsg;
61 sMsg << sFunc << " failed with Win32 error code " << Num2Hex(nWin32Error) << "!";
63 throw std::exception(sMsg.str().c_str());
66 void ThrowLastError(const char* sFunc) { ThrowWin32Error(sFunc, GetLastError()); }
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */