source: trunk/synergy/lib/platform/CPMUtil.cpp

Last change on this file was 2765, checked in by bird, 19 years ago

hacking on keyboard stuff.

File size: 2.8 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2004 Chris Schoeneman
4 * Copyright (C) 2006 Knut St. Osmundsen
5 *
6 * This package is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * found in the file COPYING that should have accompanied this file.
9 *
10 * This package is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include "CPMUtil.h"
17#include "CStringUtil.h"
18#include <stdio.h>
19#include <process.h>
20
21//
22// CPMUtil
23//
24
25CString
26CPMUtil::getString(HMODULE hmod, ULONG id)
27{
28 char szBuf[1024];
29
30 // load string
31 LONG cch = WinLoadString(WinQueryAnchorBlock(HWND_DESKTOP), hmod, id, sizeof(szBuf), (PSZ)szBuf);
32 if(cch < 0) {
33 szBuf[cch] = '\0';
34 char *psz = szBuf;
35 return psz;
36 }
37 return "";
38}
39
40CString
41CPMUtil::getErrorString(HMODULE hmod, ULONG error, ULONG id)
42{
43#if 1
44 char szMsg[80];
45 snprintf(szMsg, sizeof(szMsg), "sys error %#lx (%d)\n", error, error);
46 char *pszMsg = szMsg;
47 return CString(pszMsg);
48
49#else
50 char* buffer;
51 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
52 FORMAT_MESSAGE_IGNORE_INSERTS |
53 FORMAT_MESSAGE_FROM_SYSTEM,
54 0,
55 error,
56 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
57 (LPTSTR)&buffer,
58 0,
59 NULL) == 0) {
60 CString errorString = CStringUtil::print("%d", error);
61 return CStringUtil::format(getString(hinstance, id).c_str(),
62 errorString.c_str());
63 }
64 else {
65 CString result(buffer);
66 LocalFree(buffer);
67 return result;
68 }
69#endif
70}
71
72HAB CPMUtil::getHAB(void)
73{
74 return WinQueryAnchorBlock(HWND_DESKTOP);
75}
76
77HMQ CPMUtil::getHMQ(HAB hab /* = NULLHANDLE */)
78{
79 if (hab == NULLHANDLE) {
80 hab = getHAB();
81 }
82 return WinQueueFromID(hab, getpid(), _gettid());
83}
84
85
86/** dynamic resolver */
87USHORT APIENTRY WinTranslateChar2(USHORT usCodePage,
88 PUSHORT pusCharInOut,
89 PULONG pulDeadKeyInfo,
90 WINTCOP enmOperation,
91 PUSHORT pfShiftState)
92{
93 static USHORT (* APIENTRY pfnWinTranslateChar2)(USHORT, PUSHORT, PULONG, WINTCOP, PUSHORT) = NULL;
94 if (!pfnWinTranslateChar2) {
95 /* resolve it */
96 HMODULE hmod;
97 if ( DosLoadModule(NULL, 0, (PCSZ)"PMWIN", &hmod) != NO_ERROR
98 || DosQueryProcAddr(hmod, 1070, NULL, (PPFN)&pfnWinTranslateChar2) != NO_ERROR) {
99 asm("int3");
100 *pusCharInOut = 0;
101 return 0;
102 }
103 DosFreeModule(hmod);
104 }
105 return pfnWinTranslateChar2(usCodePage, pusCharInOut, pulDeadKeyInfo, enmOperation, pfShiftState);
106}
107
Note: See TracBrowser for help on using the repository browser.