ReactOS  0.4.15-dev-5137-g826bd41
utils.c File Reference
#include "precomp.h"
Include dependency graph for utils.c:

Go to the source code of this file.

Classes

struct  tagBITMAPCOREINFO256
 

Macros

#define INITIAL_COUNT   0x40
 
#define MAX_RETRY   10
 
#define GET_FN(name)
 
#define MAX_PRELOAD   0x400
 
#define GET_FN(name)
 

Typedefs

typedef struct tagBITMAPCOREINFO256 BITMAPCOREINFO256
 
typedef struct tagBITMAPCOREINFO256PBITMAPCOREINFO256
 
typedef BOOL(WINAPIFN_GetFileVersionInfoW) (LPCWSTR, DWORD, DWORD, LPVOID)
 
typedef DWORD(WINAPIFN_GetFileVersionInfoSizeW) (LPCWSTR, LPDWORD)
 
typedef BOOL(WINAPIFN_VerQueryValueW) (LPCVOID, LPCWSTR, LPVOID *, PUINT)
 
typedef INT(WINAPIFN_LZOpenFileW) (LPWSTR, LPOFSTRUCT, WORD)
 
typedef LONG(WINAPIFN_LZCopy) (INT, INT)
 
typedef VOID(WINAPIFN_LZClose) (INT)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (imm)
 
HRESULT APIENTRY Imm32StrToUInt (LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase)
 
HRESULT APIENTRY Imm32UIntToStr (DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff)
 
BOOL APIENTRY Imm32IsSystemJapaneseOrKorean (VOID)
 
HBITMAP Imm32LoadBitmapFromBytes (const BYTE *pb)
 
BOOL Imm32StoreBitmapToBytes (HBITMAP hbm, LPBYTE pbData, DWORD cbDataMax)
 
BOOL WINAPI Imm32IsImcAnsi (HIMC hIMC)
 
LPWSTR APIENTRY Imm32WideFromAnsi (LPCSTR pszA)
 
LPSTR APIENTRY Imm32AnsiFromWide (LPCWSTR pszW)
 
LONG APIENTRY IchWideFromAnsi (LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage)
 
LONG APIENTRY IchAnsiFromWide (LONG cchWide, LPCWSTR pchWide, UINT uCodePage)
 
BOOL Imm32GetSystemLibraryPath (LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName)
 
VOID APIENTRY LogFontAnsiToWide (const LOGFONTA *plfA, LPLOGFONTW plfW)
 
VOID APIENTRY LogFontWideToAnsi (const LOGFONTW *plfW, LPLOGFONTA plfA)
 
static PVOID FASTCALL DesktopPtrToUser (PVOID ptr)
 
LPVOID FASTCALL ValidateHandleNoErr (HANDLE hObject, UINT uType)
 
LPVOID FASTCALL ValidateHandle (HANDLE hObject, UINT uType)
 
BOOL APIENTRY Imm32CheckImcProcess (PIMC pIMC)
 
LPVOID APIENTRY ImmLocalAlloc (DWORD dwFlags, DWORD dwBytes)
 
BOOL APIENTRY Imm32MakeIMENotify (HIMC hIMC, HWND hwnd, DWORD dwAction, DWORD_PTR dwIndex, DWORD_PTR dwValue, DWORD_PTR dwCommand, DWORD_PTR dwData)
 
DWORD APIENTRY Imm32BuildHimcList (DWORD dwThreadId, HIMC **pphList)
 
INT APIENTRY Imm32ImeMenuAnsiToWide (const IMEMENUITEMINFOA *pItemA, LPIMEMENUITEMINFOW pItemW, UINT uCodePage, BOOL bBitmap)
 
INT APIENTRY Imm32ImeMenuWideToAnsi (const IMEMENUITEMINFOW *pItemW, LPIMEMENUITEMINFOA pItemA, UINT uCodePage)
 
PIME_STATE APIENTRY Imm32FetchImeState (LPINPUTCONTEXTDX pIC, HKL hKL)
 
PIME_SUBSTATE APIENTRY Imm32FetchImeSubState (PIME_STATE pState, HKL hKL)
 
BOOL APIENTRY Imm32LoadImeStateSentence (LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL)
 
BOOL APIENTRY Imm32SaveImeStateSentence (LPINPUTCONTEXTDX pIC, PIME_STATE pState, HKL hKL)
 
DWORD APIENTRY Imm32ReconvertWideFromAnsi (LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage)
 
DWORD APIENTRY Imm32ReconvertAnsiFromWide (LPRECONVERTSTRING pDest, const RECONVERTSTRING *pSrc, UINT uCodePage)
 
static BOOL APIENTRY Imm32LoadImeFixedInfo (PIMEINFOEX pInfoEx, LPCVOID pVerInfo)
 
static LPWSTR APIENTRY Imm32GetVerInfoValue (LPCVOID pVerInfo, LPWSTR pszKey, DWORD cchKey, LPCWSTR pszName)
 
BOOL APIENTRY Imm32LoadImeLangAndDesc (PIMEINFOEX pInfoEx, LPCVOID pVerInfo)
 
BOOL APIENTRY Imm32LoadImeVerInfo (PIMEINFOEX pImeInfoEx)
 
HKL APIENTRY Imm32AssignNewLayout (UINT cKLs, const REG_IME *pLayouts, WORD wLangID)
 
UINT APIENTRY Imm32GetImeLayout (PREG_IME pLayouts, UINT cLayouts)
 
BOOL APIENTRY Imm32WriteImeLayout (HKL hKL, LPCWSTR pchFilePart, LPCWSTR pszLayout)
 
BOOL APIENTRY Imm32CopyImeFile (LPWSTR pszOldFile, LPCWSTR pszNewFile)
 
HIMCC WINAPI ImmCreateIMCC (DWORD size)
 
HIMCC WINAPI ImmDestroyIMCC (HIMCC block)
 
LPVOID WINAPI ImmLockIMCC (HIMCC imcc)
 
BOOL WINAPI ImmUnlockIMCC (HIMCC imcc)
 
DWORD WINAPI ImmGetIMCCLockCount (HIMCC imcc)
 
HIMCC WINAPI ImmReSizeIMCC (HIMCC imcc, DWORD size)
 
DWORD WINAPI ImmGetIMCCSize (HIMCC imcc)
 
DWORD WINAPI ImmGetIMCLockCount (HIMC hIMC)
 
BOOL WINAPI ImmIMPGetIMEA (HWND hWnd, LPIMEPROA pImePro)
 
BOOL WINAPI ImmIMPGetIMEW (HWND hWnd, LPIMEPROW pImePro)
 
BOOL WINAPI ImmIMPQueryIMEA (LPIMEPROA pImePro)
 
BOOL WINAPI ImmIMPQueryIMEW (LPIMEPROW pImePro)
 
BOOL WINAPI ImmIMPSetIMEA (HWND hWnd, LPIMEPROA pImePro)
 
BOOL WINAPI ImmIMPSetIMEW (HWND hWnd, LPIMEPROW pImePro)
 

Variables

HANDLE ghImmHeap = NULL
 
static FN_GetFileVersionInfoW s_fnGetFileVersionInfoW = NULL
 
static FN_GetFileVersionInfoSizeW s_fnGetFileVersionInfoSizeW = NULL
 
static FN_VerQueryValueW s_fnVerQueryValueW = NULL
 

Macro Definition Documentation

◆ GET_FN [1/2]

#define GET_FN (   name)
Value:
do { \
s_fn##name = (FN_##name)GetProcAddress(hinstVersion, #name); \
if (!s_fn##name) goto Quit; \
} while (0)
Definition: name.c:38
#define GetProcAddress(x, y)
Definition: compat.h:612
GLuint const GLchar * name
Definition: glext.h:6031

◆ GET_FN [2/2]

#define GET_FN (   name)
Value:
do { \
fn##name = (FN_##name)GetProcAddress(hinstLZ32, #name); \
if (!fn##name) goto Quit; \
} while (0)
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
Definition: name.c:38
#define GetProcAddress(x, y)
Definition: compat.h:612
GLuint const GLchar * name
Definition: glext.h:6031

◆ INITIAL_COUNT

#define INITIAL_COUNT   0x40

◆ MAX_PRELOAD

#define MAX_PRELOAD   0x400

◆ MAX_RETRY

#define MAX_RETRY   10

Typedef Documentation

◆ BITMAPCOREINFO256

◆ FN_GetFileVersionInfoSizeW

typedef DWORD(WINAPI * FN_GetFileVersionInfoSizeW) (LPCWSTR, LPDWORD)

Definition at line 683 of file utils.c.

◆ FN_GetFileVersionInfoW

typedef BOOL(WINAPI * FN_GetFileVersionInfoW) (LPCWSTR, DWORD, DWORD, LPVOID)

Definition at line 682 of file utils.c.

◆ FN_LZClose

typedef VOID(WINAPI * FN_LZClose) (INT)

Definition at line 1028 of file utils.c.

◆ FN_LZCopy

typedef LONG(WINAPI * FN_LZCopy) (INT, INT)

Definition at line 1027 of file utils.c.

◆ FN_LZOpenFileW

typedef INT(WINAPI * FN_LZOpenFileW) (LPWSTR, LPOFSTRUCT, WORD)

Definition at line 1026 of file utils.c.

◆ FN_VerQueryValueW

typedef BOOL(WINAPI * FN_VerQueryValueW) (LPCVOID, LPCWSTR, LPVOID *, PUINT)

Definition at line 684 of file utils.c.

◆ PBITMAPCOREINFO256

Function Documentation

◆ DesktopPtrToUser()

static PVOID FASTCALL DesktopPtrToUser ( PVOID  ptr)
static

Definition at line 278 of file utils.c.

279 {
281  PDESKTOPINFO pdi = pci->pDeskInfo;
282 
283  ASSERT(ptr != NULL);
284  ASSERT(pdi != NULL);
285  if (pdi->pvDesktopBase <= ptr && ptr < pdi->pvDesktopLimit)
286  return (PVOID)((ULONG_PTR)ptr - pci->ulClientDelta);
287  else
289 }
DWORD_PTR NTAPI NtUserCallOneParam(DWORD_PTR Param, DWORD Routine)
Definition: simplecall.c:158
#define GetWin32ClientInfo()
Definition: ntuser.h:335
static PVOID ptr
Definition: dispmode.c:27
ULONG_PTR ulClientDelta
Definition: ntuser.h:309
#define ASSERT(a)
Definition: mode.c:44
PDESKTOPINFO pDeskInfo
Definition: ntuser.h:308
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define ONEPARAM_ROUTINE_GETDESKTOPMAPPING
Definition: ntuser.h:3666
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO * pdi
Definition: winddi.h:3553

Referenced by CallNextHookEx(), GetAncestor(), GetClassLongA(), GetClassLongW(), GetClassWord(), GetLastActivePopup(), GetMenuItemInfo_common(), GetMenuState(), GetMenuStringA(), GetMenuStringW(), GetParent(), GetSubMenu(), GetThreadDesktopWnd(), GetWindow(), GetWindowInfo(), IntCallMessageProc(), IntFindChildWindowToOwner(), IntGetMenuDefaultItem(), IntGetSBData(), IntGetWndProc(), IntScrollGetScrollBarRect(), IsChild(), IsWindowVisible(), MENU_FindItem(), RealDefWindowProcA(), RealDefWindowProcW(), User32DefWindowProc(), ValidateHandle(), and ValidateHandleNoErr().

◆ IchAnsiFromWide()

LONG APIENTRY IchAnsiFromWide ( LONG  cchWide,
LPCWSTR  pchWide,
UINT  uCodePage 
)

Definition at line 230 of file utils.c.

231 {
232  LONG cb, cchAnsi;
233  for (cchAnsi = 0; cchWide > 0; ++cchAnsi, ++pchWide, --cchWide)
234  {
235  cb = WideCharToMultiByte(uCodePage, 0, pchWide, 1, NULL, 0, NULL, NULL);
236  if (cb > 1)
237  ++cchAnsi;
238  }
239  return cchAnsi;
240 }
#define WideCharToMultiByte
Definition: compat.h:111
long LONG
Definition: pedump.c:60
#define NULL
Definition: types.h:112
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32

Referenced by Imm32GetCompStrA(), Imm32ProcessRequest(), and Imm32ReconvertAnsiFromWide().

◆ IchWideFromAnsi()

LONG APIENTRY IchWideFromAnsi ( LONG  cchAnsi,
LPCSTR  pchAnsi,
UINT  uCodePage 
)

Definition at line 210 of file utils.c.

211 {
212  LONG cchWide;
213  for (cchWide = 0; cchAnsi > 0; ++cchWide)
214  {
215  if (IsDBCSLeadByteEx(uCodePage, *pchAnsi) && pchAnsi[1])
216  {
217  cchAnsi -= 2;
218  pchAnsi += 2;
219  }
220  else
221  {
222  --cchAnsi;
223  ++pchAnsi;
224  }
225  }
226  return cchWide;
227 }
BOOL WINAPI IsDBCSLeadByteEx(UINT CodePage, BYTE TestByte)
Definition: nls.c:2248
long LONG
Definition: pedump.c:60

Referenced by Imm32GetCompStrW(), Imm32ProcessRequest(), and Imm32ReconvertWideFromAnsi().

◆ Imm32AnsiFromWide()

LPSTR APIENTRY Imm32AnsiFromWide ( LPCWSTR  pszW)

Definition at line 197 of file utils.c.

198 {
199  INT cchW = lstrlenW(pszW);
200  INT cchA = (cchW + 1) * sizeof(WCHAR);
201  LPSTR pszA = ImmLocalAlloc(0, cchA);
202  if (!pszA)
203  return NULL;
204  cchA = WideCharToMultiByte(CP_ACP, 0, pszW, cchW, pszA, cchA, NULL, NULL);
205  pszA[cchA] = 0;
206  return pszA;
207 }
#define WideCharToMultiByte
Definition: compat.h:111
#define CP_ACP
Definition: compat.h:109
char * LPSTR
Definition: xmlstorage.h:182
#define lstrlenW
Definition: compat.h:609
int32_t INT
Definition: typedefs.h:58
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:355
#define NULL
Definition: types.h:112

Referenced by Imm32EnumWordProcW2A(), ImmConfigureIMEW(), ImmEnumRegisterWordW(), ImmGetConversionListW(), ImmRegisterWordW(), and ImmUnregisterWordW().

◆ Imm32AssignNewLayout()

HKL APIENTRY Imm32AssignNewLayout ( UINT  cKLs,
const REG_IME pLayouts,
WORD  wLangID 
)

Definition at line 819 of file utils.c.

820 {
821  UINT iKL, wID, wLow = 0xE0FF, wHigh = 0xE01F, wNextID = 0;
822 
823  for (iKL = 0; iKL < cKLs; ++iKL)
824  {
825  wHigh = max(wHigh, HIWORD(pLayouts[iKL].hKL));
826  wLow = min(wLow, HIWORD(pLayouts[iKL].hKL));
827  }
828 
829  if (wHigh < 0xE0FF)
830  {
831  wNextID = wHigh + 1;
832  }
833  else if (wLow > 0xE001)
834  {
835  wNextID = wLow - 1;
836  }
837  else
838  {
839  for (wID = 0xE020; wID <= 0xE0FF; ++wID)
840  {
841  for (iKL = 0; iKL < cKLs; ++iKL)
842  {
843  if (LOWORD(pLayouts[iKL].hKL) == wLangID &&
844  HIWORD(pLayouts[iKL].hKL) == wID)
845  {
846  break;
847  }
848  }
849 
850  if (iKL >= cKLs)
851  break;
852  }
853 
854  if (wID <= 0xE0FF)
855  wNextID = wID;
856  }
857 
858  if (!wNextID)
859  return NULL;
860 
861  return (HKL)(DWORD_PTR)MAKELONG(wLangID, wNextID);
862 }
#define max(a, b)
Definition: svc.c:63
#define DWORD_PTR
Definition: treelist.c:76
#define MAKELONG(a, b)
Definition: typedefs.h:249
UINT_PTR HKL
Definition: msctf.idl:101
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define HIWORD(l)
Definition: typedefs.h:247
#define LOWORD(l)
Definition: pedump.c:82

Referenced by ImmInstallIMEW().

◆ Imm32BuildHimcList()

DWORD APIENTRY Imm32BuildHimcList ( DWORD  dwThreadId,
HIMC **  pphList 
)

Definition at line 400 of file utils.c.

401 {
402 #define INITIAL_COUNT 0x40
403 #define MAX_RETRY 10
405  DWORD dwCount = INITIAL_COUNT, cRetry = 0;
406  HIMC *phNewList;
407 
408  phNewList = ImmLocalAlloc(0, dwCount * sizeof(HIMC));
409  if (phNewList == NULL)
410  return 0;
411 
412  Status = NtUserBuildHimcList(dwThreadId, dwCount, phNewList, &dwCount);
414  {
415  ImmLocalFree(phNewList);
416  if (cRetry++ >= MAX_RETRY)
417  return 0;
418 
419  phNewList = ImmLocalAlloc(0, dwCount * sizeof(HIMC));
420  if (phNewList == NULL)
421  return 0;
422 
423  Status = NtUserBuildHimcList(dwThreadId, dwCount, phNewList, &dwCount);
424  }
425 
426  if (NT_ERROR(Status) || !dwCount)
427  {
428  ImmLocalFree(phNewList);
429  return 0;
430  }
431 
432  *pphList = phNewList;
433  return dwCount;
434 #undef INITIAL_COUNT
435 #undef MAX_RETRY
436 }
NTSTATUS NTAPI NtUserBuildHimcList(DWORD dwThreadId, DWORD dwCount, HIMC *phList, LPDWORD pdwCount)
Definition: ime.c:698
#define MAX_RETRY
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
DWORD HIMC
Definition: dimm.idl:75
Status
Definition: gdiplustypes.h:24
unsigned long DWORD
Definition: ntddk_ex.h:95
#define NT_ERROR(Status)
Definition: umtypes.h:106
#define ImmLocalFree(lpData)
Definition: precomp.h:89
DWORD dwThreadId
Definition: fdebug.c:31
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:355
#define NULL
Definition: types.h:112
#define INITIAL_COUNT

Referenced by ImmEnumInputContext().

◆ Imm32CheckImcProcess()

BOOL APIENTRY Imm32CheckImcProcess ( PIMC  pIMC)

Definition at line 342 of file utils.c.

343 {
344  HIMC hIMC;
345  DWORD dwProcessID;
346  if (pIMC->head.pti == Imm32CurrentPti())
347  return TRUE;
348 
349  hIMC = pIMC->head.h;
350  dwProcessID = (DWORD)NtUserQueryInputContext(hIMC, QIC_INPUTPROCESSID);
351  return dwProcessID == (DWORD_PTR)NtCurrentTeb()->ClientId.UniqueProcess;
352 }
#define DWORD_PTR
Definition: treelist.c:76
#define TRUE
Definition: types.h:120
static PTHREADINFO FASTCALL Imm32CurrentPti(VOID)
Definition: precomp.h:160
#define DWORD
Definition: nt_native.h:44
DWORD HIMC
Definition: dimm.idl:75
DWORD_PTR NTAPI NtUserQueryInputContext(HIMC hIMC, DWORD dwType)
Definition: ime.c:1794
unsigned long DWORD
Definition: ntddk_ex.h:95
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
THRDESKHEAD head
Definition: ntuser.h:192

Referenced by ImmLockClientImc().

◆ Imm32CopyImeFile()

BOOL APIENTRY Imm32CopyImeFile ( LPWSTR  pszOldFile,
LPCWSTR  pszNewFile 
)

Definition at line 1031 of file utils.c.

1032 {
1033  BOOL ret = FALSE, bLoaded = FALSE;
1034  HMODULE hinstLZ32;
1035  WCHAR szLZ32Path[MAX_PATH];
1036  CHAR szDestA[MAX_PATH];
1037  OFSTRUCT OFStruct;
1038  FN_LZOpenFileW fnLZOpenFileW;
1039  FN_LZCopy fnLZCopy;
1040  FN_LZClose fnLZClose;
1041  HFILE hfDest, hfSrc;
1042 
1043  /* Load LZ32.dll for copying/decompressing file */
1044  Imm32GetSystemLibraryPath(szLZ32Path, _countof(szLZ32Path), L"LZ32");
1045  hinstLZ32 = GetModuleHandleW(szLZ32Path);
1046  if (!hinstLZ32)
1047  {
1048  hinstLZ32 = LoadLibraryW(szLZ32Path);
1049  if (!hinstLZ32)
1050  return FALSE;
1051  bLoaded = TRUE;
1052  }
1053 
1054 #define GET_FN(name) do { \
1055  fn##name = (FN_##name)GetProcAddress(hinstLZ32, #name); \
1056  if (!fn##name) goto Quit; \
1057 } while (0)
1059  GET_FN(LZCopy);
1060  GET_FN(LZClose);
1061 #undef GET_FN
1062 
1063  if (!WideCharToMultiByte(CP_ACP, 0, pszNewFile, -1, szDestA, _countof(szDestA), NULL, NULL))
1064  goto Quit;
1065  szDestA[_countof(szDestA) - 1] = 0;
1066 
1067  hfSrc = fnLZOpenFileW(pszOldFile, &OFStruct, OF_READ);
1068  if (hfSrc < 0)
1069  goto Quit;
1070 
1071  hfDest = OpenFile(szDestA, &OFStruct, OF_CREATE);
1072  if (hfDest != HFILE_ERROR)
1073  {
1074  ret = (fnLZCopy(hfSrc, hfDest) >= 0);
1075  _lclose(hfDest);
1076  }
1077 
1078  fnLZClose(hfSrc);
1079 
1080 Quit:
1081  if (bLoaded)
1082  FreeLibrary(hinstLZ32);
1083  return ret;
1084 }
#define OF_READ
Definition: winbase.h:116
#define WideCharToMultiByte
Definition: compat.h:111
#define TRUE
Definition: types.h:120
#define CP_ACP
Definition: compat.h:109
char CHAR
Definition: xmlstorage.h:175
HFILE WINAPI LZOpenFileW(LPWSTR fn, LPOFSTRUCT ofs, WORD mode)
Definition: lzexpand.c:585
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
void WINAPI LZClose(HFILE fd)
Definition: lzexpand.c:600
#define L(x)
Definition: ntvdm.h:50
#define HFILE_ERROR
Definition: winbase.h:111
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
INT(WINAPI * FN_LZOpenFileW)(LPWSTR, LPOFSTRUCT, WORD)
Definition: utils.c:1026
LONG(WINAPI * FN_LZCopy)(INT, INT)
Definition: utils.c:1027
#define LoadLibraryW(x)
Definition: compat.h:606
VOID(WINAPI * FN_LZClose)(INT)
Definition: utils.c:1028
HFILE WINAPI OpenFile(LPCSTR lpFileName, LPOFSTRUCT lpReOpenBuff, UINT uStyle)
Definition: create.c:368
#define FreeLibrary(x)
Definition: compat.h:607
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
#define GET_FN(name)
int ret
BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName)
Definition: utils.c:243
LONG WINAPI LZCopy(HFILE src, HFILE dest)
Definition: lzexpand.c:472
#define NULL
Definition: types.h:112
#define OF_CREATE
Definition: winbase.h:125
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
int HFILE
Definition: windef.h:298

Referenced by ImmInstallIMEW().

◆ Imm32FetchImeState()

PIME_STATE APIENTRY Imm32FetchImeState ( LPINPUTCONTEXTDX  pIC,
HKL  hKL 
)

Definition at line 491 of file utils.c.

492 {
493  PIME_STATE pState;
494  WORD Lang = PRIMARYLANGID(LOWORD(hKL));
495  for (pState = pIC->pState; pState; pState = pState->pNext)
496  {
497  if (pState->wLang == Lang)
498  break;
499  }
500  if (!pState)
501  {
502  pState = ImmLocalAlloc(HEAP_ZERO_MEMORY, sizeof(IME_STATE));
503  if (pState)
504  {
505  pState->wLang = Lang;
506  pState->pNext = pIC->pState;
507  pIC->pState = pState;
508  }
509  }
510  return pState;
511 }
WORD wLang
Definition: immdev.h:209
unsigned short WORD
Definition: ntddk_ex.h:93
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:355
struct IME_STATE * pState
Definition: immdev.h:128
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
struct IME_STATE * pNext
Definition: immdev.h:208
#define LOWORD(l)
Definition: pedump.c:82
#define PRIMARYLANGID(l)
Definition: nls.h:16

Referenced by Imm32SelectInputContext().

◆ Imm32FetchImeSubState()

PIME_SUBSTATE APIENTRY Imm32FetchImeSubState ( PIME_STATE  pState,
HKL  hKL 
)

Definition at line 515 of file utils.c.

516 {
517  PIME_SUBSTATE pSubState;
518  for (pSubState = pState->pSubState; pSubState; pSubState = pSubState->pNext)
519  {
520  if (pSubState->hKL == hKL)
521  return pSubState;
522  }
523  pSubState = ImmLocalAlloc(0, sizeof(IME_SUBSTATE));
524  if (!pSubState)
525  return NULL;
526  pSubState->dwValue = 0;
527  pSubState->hKL = hKL;
528  pSubState->pNext = pState->pSubState;
529  pState->pSubState = pSubState;
530  return pSubState;
531 }
PIME_SUBSTATE pSubState
Definition: immdev.h:214
DWORD dwValue
Definition: immdev.h:199
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:355
#define NULL
Definition: types.h:112
struct IME_SUBSTATE * pNext
Definition: immdev.h:197

Referenced by Imm32LoadImeStateSentence(), and Imm32SaveImeStateSentence().

◆ Imm32GetImeLayout()

UINT APIENTRY Imm32GetImeLayout ( PREG_IME  pLayouts,
UINT  cLayouts 
)

Definition at line 865 of file utils.c.

866 {
867  HKEY hkeyLayouts, hkeyIME;
868  WCHAR szImeFileName[80], szImeKey[20];
869  UINT iKey, nCount;
870  DWORD cbData;
871  LONG lError;
872  ULONG Value;
873  HKL hKL;
874 
875  /* Open the registry keyboard layouts */
876  lError = RegOpenKeyW(HKEY_LOCAL_MACHINE, REGKEY_KEYBOARD_LAYOUTS, &hkeyLayouts);
877  if (lError != ERROR_SUCCESS)
878  return 0;
879 
880  for (iKey = nCount = 0; ; ++iKey)
881  {
882  /* Get the key name */
883  lError = RegEnumKeyW(hkeyLayouts, iKey, szImeKey, _countof(szImeKey));
884  if (lError != ERROR_SUCCESS)
885  break;
886 
887  if (szImeKey[0] != L'E' && szImeKey[0] != L'e')
888  continue; /* Not an IME layout */
889 
890  if (pLayouts == NULL) /* for counting only */
891  {
892  ++nCount;
893  continue;
894  }
895 
896  if (cLayouts <= nCount)
897  break;
898 
899  lError = RegOpenKeyW(hkeyLayouts, szImeKey, &hkeyIME); /* Open the IME key */
900  if (lError != ERROR_SUCCESS)
901  break;
902 
903  /* Load the "Ime File" value */
904  szImeFileName[0] = 0;
905  cbData = sizeof(szImeFileName);
906  RegQueryValueExW(hkeyIME, L"Ime File", NULL, NULL, (LPBYTE)szImeFileName, &cbData);
907  szImeFileName[_countof(szImeFileName) - 1] = 0;
908 
909  RegCloseKey(hkeyIME);
910 
911  /* We don't allow the invalid "IME File" values for security reason */
912  if (!szImeFileName[0] || wcscspn(szImeFileName, L":\\/") != wcslen(szImeFileName))
913  break;
914 
915  Imm32StrToUInt(szImeKey, &Value, 16);
916  hKL = (HKL)(DWORD_PTR)Value;
917  if (!IS_IME_HKL(hKL))
918  break;
919 
920  /* Store the IME key and the IME filename */
921  pLayouts[nCount].hKL = hKL;
922  StringCchCopyW(pLayouts[nCount].szImeKey, _countof(pLayouts[nCount].szImeKey), szImeKey);
923  CharUpperW(szImeFileName);
924  StringCchCopyW(pLayouts[nCount].szFileName, _countof(pLayouts[nCount].szFileName),
925  szImeFileName);
926  ++nCount;
927  }
928 
929  RegCloseKey(hkeyLayouts);
930  return nCount;
931 }
#define ERROR_SUCCESS
Definition: deptool.c:10
_Check_return_ _CRTIMP size_t __cdecl wcscspn(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
HRESULT APIENTRY Imm32StrToUInt(LPCWSTR pszText, LPDWORD pdwValue, ULONG nBase)
Definition: utils.c:20
HKL hKL
Definition: precomp.h:67
LPWSTR WINAPI CharUpperW(_Inout_ LPWSTR)
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
long LONG
Definition: pedump.c:60
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3291
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4120
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define REGKEY_KEYBOARD_LAYOUTS
Definition: precomp.h:60
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT_PTR HKL
Definition: msctf.idl:101
uint32_t DWORD_PTR
Definition: typedefs.h:65
LONG WINAPI RegEnumKeyW(HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cbName)
Definition: reg.c:2416
#define IS_IME_HKL(hKL)
Definition: input.h:88
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
unsigned int ULONG
Definition: retypes.h:1
#define RegCloseKey(hKey)
Definition: registry.h:47
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by ImmInstallIMEW().

◆ Imm32GetSystemLibraryPath()

BOOL Imm32GetSystemLibraryPath ( LPWSTR  pszPath,
DWORD  cchPath,
LPCWSTR  pszFileName 
)

Definition at line 243 of file utils.c.

244 {
245  if (!pszFileName[0] || !GetSystemDirectoryW(pszPath, cchPath))
246  return FALSE;
247  StringCchCatW(pszPath, cchPath, L"\\");
248  StringCchCatW(pszPath, cchPath, pszFileName);
249  return TRUE;
250 }
#define TRUE
Definition: types.h:120
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313

Referenced by Imm32CopyImeFile(), Imm32LoadIME(), Imm32LoadImeVerInfo(), and ImmInstallIMEW().

◆ Imm32GetVerInfoValue()

static LPWSTR APIENTRY Imm32GetVerInfoValue ( LPCVOID  pVerInfo,
LPWSTR  pszKey,
DWORD  cchKey,
LPCWSTR  pszName 
)
static

Definition at line 709 of file utils.c.

710 {
711  size_t cchExtra;
712  LPWSTR pszValue;
713  UINT cbValue = 0;
714 
715  StringCchLengthW(pszKey, cchKey, &cchExtra);
716 
717  StringCchCatW(pszKey, cchKey, pszName);
718  s_fnVerQueryValueW(pVerInfo, pszKey, (LPVOID*)&pszValue, &cbValue);
719  pszKey[cchExtra] = 0;
720 
721  return (cbValue ? pszValue : NULL);
722 }
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
static FN_VerQueryValueW s_fnVerQueryValueW
Definition: utils.c:688
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
STRSAFEAPI StringCchLengthW(STRSAFE_LPCWSTR psz, size_t cchMax, size_t *pcchLength)
Definition: strsafe.h:842
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by Imm32LoadImeLangAndDesc().

◆ Imm32ImeMenuAnsiToWide()

INT APIENTRY Imm32ImeMenuAnsiToWide ( const IMEMENUITEMINFOA pItemA,
LPIMEMENUITEMINFOW  pItemW,
UINT  uCodePage,
BOOL  bBitmap 
)

Definition at line 440 of file utils.c.

442 {
443  INT ret;
444  pItemW->cbSize = pItemA->cbSize;
445  pItemW->fType = pItemA->fType;
446  pItemW->fState = pItemA->fState;
447  pItemW->wID = pItemA->wID;
448  if (bBitmap)
449  {
450  pItemW->hbmpChecked = pItemA->hbmpChecked;
451  pItemW->hbmpUnchecked = pItemA->hbmpUnchecked;
452  pItemW->hbmpItem = pItemA->hbmpItem;
453  }
454  pItemW->dwItemData = pItemA->dwItemData;
455  ret = MultiByteToWideChar(uCodePage, 0, pItemA->szString, -1,
456  pItemW->szString, _countof(pItemW->szString));
457  if (ret >= _countof(pItemW->szString))
458  {
459  ret = 0;
460  pItemW->szString[0] = 0;
461  }
462  return ret;
463 }
HBITMAP hbmpChecked
Definition: imm.h:129
DWORD dwItemData
Definition: imm.h:131
int32_t INT
Definition: typedefs.h:58
WCHAR szString[IMEMENUITEM_STRING_SIZE]
Definition: imm.h:132
HBITMAP hbmpUnchecked
Definition: dimm.idl:123
#define _countof(array)
Definition: sndvol32.h:68
int ret
DWORD dwItemData
Definition: dimm.idl:124
HBITMAP hbmpItem
Definition: dimm.idl:126
#define MultiByteToWideChar
Definition: compat.h:110
HBITMAP hbmpChecked
Definition: dimm.idl:122
HBITMAP hbmpItem
Definition: imm.h:133
HBITMAP hbmpUnchecked
Definition: imm.h:130
CHAR szString[IMEMENUITEM_STRING_SIZE]
Definition: dimm.idl:125

Referenced by ImmGetImeMenuItemsAW().

◆ Imm32ImeMenuWideToAnsi()

INT APIENTRY Imm32ImeMenuWideToAnsi ( const IMEMENUITEMINFOW pItemW,
LPIMEMENUITEMINFOA  pItemA,
UINT  uCodePage 
)

Definition at line 467 of file utils.c.

469 {
470  INT ret;
471  pItemA->cbSize = pItemW->cbSize;
472  pItemA->fType = pItemW->fType;
473  pItemA->fState = pItemW->fState;
474  pItemA->wID = pItemW->wID;
475  pItemA->hbmpChecked = pItemW->hbmpChecked;
476  pItemA->hbmpUnchecked = pItemW->hbmpUnchecked;
477  pItemA->dwItemData = pItemW->dwItemData;
478  pItemA->hbmpItem = pItemW->hbmpItem;
479  ret = WideCharToMultiByte(uCodePage, 0, pItemW->szString, -1,
480  pItemA->szString, _countof(pItemA->szString), NULL, NULL);
481  if (ret >= _countof(pItemA->szString))
482  {
483  ret = 0;
484  pItemA->szString[0] = 0;
485  }
486  return ret;
487 }
#define WideCharToMultiByte
Definition: compat.h:111
HBITMAP hbmpChecked
Definition: dimm.idl:134
HBITMAP hbmpUnchecked
Definition: imm.h:117
int32_t INT
Definition: typedefs.h:58
HBITMAP hbmpUnchecked
Definition: dimm.idl:135
DWORD dwItemData
Definition: dimm.idl:136
DWORD dwItemData
Definition: imm.h:118
HBITMAP hbmpItem
Definition: dimm.idl:138
#define _countof(array)
Definition: sndvol32.h:68
HBITMAP hbmpChecked
Definition: imm.h:116
int ret
HBITMAP hbmpItem
Definition: imm.h:120
CHAR szString[IMEMENUITEM_STRING_SIZE]
Definition: imm.h:119
WCHAR szString[IMEMENUITEM_STRING_SIZE]
Definition: dimm.idl:137
#define NULL
Definition: types.h:112

Referenced by ImmGetImeMenuItemsAW().

◆ Imm32IsImcAnsi()

BOOL WINAPI Imm32IsImcAnsi ( HIMC  hIMC)

Definition at line 175 of file utils.c.

176 {
177  BOOL ret;
178  PCLIENTIMC pClientImc = ImmLockClientImc(hIMC);
179  if (!pClientImc)
180  return -1;
181  ret = !(pClientImc->dwFlags & CLIENTIMC_WIDE);
182  ImmUnlockClientImc(pClientImc);
183  return ret;
184 }
#define CLIENTIMC_WIDE
Definition: ntuser.h:1328
unsigned int BOOL
Definition: ntddk_ex.h:94
PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc)
Definition: imm.c:901
int ret
DWORD dwFlags
Definition: ntuser.h:1308
VOID WINAPI ImmUnlockClientImc(PCLIENTIMC pClientImc)
Definition: imm.c:946

Referenced by ImmGetImeMenuItemsAW().

◆ Imm32IsSystemJapaneseOrKorean()

BOOL APIENTRY Imm32IsSystemJapaneseOrKorean ( VOID  )

Definition at line 45 of file utils.c.

46 {
47  LCID lcid = GetSystemDefaultLCID();
49  WORD wPrimary = PRIMARYLANGID(LangID);
50  return (wPrimary == LANG_JAPANESE || wPrimary == LANG_KOREAN);
51 }
DWORD LCID
Definition: nls.h:13
WORD LANGID
Definition: typedefs.h:81
#define LANG_JAPANESE
Definition: nls.h:76
LCID WINAPI GetSystemDefaultLCID(void)
Definition: lang.c:791
unsigned short WORD
Definition: ntddk_ex.h:93
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define LANG_KOREAN
Definition: nls.h:84
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1075
#define PRIMARYLANGID(l)
Definition: nls.h:16

Referenced by ImmWINNLSEnableIME(), and ImmWINNLSGetEnableStatus().

◆ Imm32LoadBitmapFromBytes()

HBITMAP Imm32LoadBitmapFromBytes ( const BYTE pb)

Definition at line 59 of file utils.c.

60 {
61  HBITMAP hbm = NULL;
62  const BITMAPCOREINFO256 *pbmci;
63  LPVOID pvBits;
64  DWORD ib, cbBytes, cColors;
65  BITMAP bm;
66 
67  cbBytes = *(const DWORD *)pb;
68  if (cbBytes == 0)
69  return NULL;
70 
71  pb += sizeof(DWORD);
72  ib = sizeof(DWORD);
73 
74  pbmci = (const BITMAPCOREINFO256 *)pb;
75  hbm = CreateDIBSection(NULL, (LPBITMAPINFO)pbmci, DIB_RGB_COLORS, &pvBits, NULL, 0);
76  if (!hbm || !GetObject(hbm, sizeof(BITMAP), &bm))
77  return NULL;
78 
79  switch (pbmci->bmciHeader.bcBitCount)
80  {
81  case 1: cColors = 2; break;
82  case 4: cColors = 16; break;
83  case 8: cColors = 256; break;
84  case 24: case 32:
85  cColors = 0;
86  break;
87  default:
89  return NULL;
90  }
91 
92  ib += sizeof(BITMAPCOREHEADER);
93  pb += sizeof(BITMAPCOREHEADER);
94 
95  ib += cColors * sizeof(RGBTRIPLE);
96  pb += cColors * sizeof(RGBTRIPLE);
97 
98  ib += bm.bmWidthBytes * bm.bmHeight;
99  if (ib > cbBytes)
100  {
101  DeleteObject(hbm);
102  return NULL;
103  }
104  CopyMemory(pvBits, pb, bm.bmWidthBytes * bm.bmHeight);
105 
106  return hbm;
107 }
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define DWORD
Definition: nt_native.h:44
struct tagRGBTRIPLE RGBTRIPLE
#define CopyMemory
Definition: winbase.h:1665
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
unsigned long DWORD
Definition: ntddk_ex.h:95
BITMAPCOREHEADER bmciHeader
Definition: utils.c:55
#define GetObject
Definition: wingdi.h:4468
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:199
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
Definition: bl.h:1330
#define NULL
Definition: types.h:112
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:367

Referenced by Imm32GetImeMenuItemWInterProcess().

◆ Imm32LoadImeFixedInfo()

static BOOL APIENTRY Imm32LoadImeFixedInfo ( PIMEINFOEX  pInfoEx,
LPCVOID  pVerInfo 
)
static

Definition at line 691 of file utils.c.

692 {
693  UINT cbFixed = 0;
694  VS_FIXEDFILEINFO *pFixed;
695  if (!s_fnVerQueryValueW(pVerInfo, L"\\", (LPVOID*)&pFixed, &cbFixed) || !cbFixed)
696  return FALSE;
697 
698  /* NOTE: The IME module must contain a version info of input method driver. */
699  if (pFixed->dwFileType != VFT_DRV || pFixed->dwFileSubtype != VFT2_DRV_INPUTMETHOD)
700  return FALSE;
701 
702  pInfoEx->dwProdVersion = pFixed->dwProductVersionMS;
703  pInfoEx->dwImeWinVersion = 0x40000;
704  return TRUE;
705 }
DWORD dwProdVersion
Definition: ntuser.h:1184
#define TRUE
Definition: types.h:120
#define VFT_DRV
Definition: verrsrc.h:77
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
static FN_VerQueryValueW s_fnVerQueryValueW
Definition: utils.c:688
unsigned int UINT
Definition: ndis.h:50
#define VFT2_DRV_INPUTMETHOD
Definition: verrsrc.h:95
DWORD dwImeWinVersion
Definition: ntuser.h:1185

Referenced by Imm32LoadImeVerInfo().

◆ Imm32LoadImeLangAndDesc()

BOOL APIENTRY Imm32LoadImeLangAndDesc ( PIMEINFOEX  pInfoEx,
LPCVOID  pVerInfo 
)

Definition at line 725 of file utils.c.

726 {
727  BOOL ret;
728  WCHAR szKey[80];
729  LPWSTR pszDesc;
730  LPWORD pw;
731  UINT cbData;
732  LANGID LangID;
733 
734  /* Getting the version info. See VerQueryValue */
735  ret = s_fnVerQueryValueW(pVerInfo, L"\\VarFileInfo\\Translation", (LPVOID*)&pw, &cbData);
736  if (!ret || !cbData)
737  return FALSE;
738 
739  if (pInfoEx->hkl == NULL)
740  pInfoEx->hkl = (HKL)(DWORD_PTR)*pw; /* This is an invalid HKL */
741 
742  /* Try the current language and the Unicode codepage (0x04B0) */
744  StringCchPrintfW(szKey, _countof(szKey), L"\\StringFileInfo\\%04X04B0\\", LangID);
745  pszDesc = Imm32GetVerInfoValue(pVerInfo, szKey, _countof(szKey), L"FileDescription");
746  if (!pszDesc)
747  {
748  /* Retry the language and codepage of the IME module */
749  StringCchPrintfW(szKey, _countof(szKey), L"\\StringFileInfo\\%04X%04X\\", pw[0], pw[1]);
750  pszDesc = Imm32GetVerInfoValue(pVerInfo, szKey, _countof(szKey), L"FileDescription");
751  }
752 
753  /* The description */
754  if (pszDesc)
755  StringCchCopyW(pInfoEx->wszImeDescription, _countof(pInfoEx->wszImeDescription), pszDesc);
756  else
757  pInfoEx->wszImeDescription[0] = 0;
758 
759  return TRUE;
760 }
#define TRUE
Definition: types.h:120
WORD LANGID
Definition: typedefs.h:81
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
int ret
#define LANGIDFROMLCID(l)
Definition: nls.h:18
UINT_PTR HKL
Definition: msctf.idl:101
uint32_t DWORD_PTR
Definition: typedefs.h:65
static LPWSTR APIENTRY Imm32GetVerInfoValue(LPCVOID pVerInfo, LPWSTR pszKey, DWORD cchKey, LPCWSTR pszName)
Definition: utils.c:709
uint16_t * LPWORD
Definition: typedefs.h:56
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
WCHAR wszImeDescription[50]
Definition: ntuser.h:1186
static FN_VerQueryValueW s_fnVerQueryValueW
Definition: utils.c:688
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
WCHAR * LPWSTR
Definition: xmlstorage.h:184
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1075
LCID WINAPI GetThreadLocale(void)
Definition: lang.c:1453

Referenced by Imm32LoadImeVerInfo().

◆ Imm32LoadImeStateSentence()

BOOL APIENTRY Imm32LoadImeStateSentence ( LPINPUTCONTEXTDX  pIC,
PIME_STATE  pState,
HKL  hKL 
)

Definition at line 535 of file utils.c.

536 {
537  PIME_SUBSTATE pSubState = Imm32FetchImeSubState(pState, hKL);
538  if (pSubState)
539  {
540  pIC->fdwSentence |= pSubState->dwValue;
541  return TRUE;
542  }
543  return FALSE;
544 }
PIME_SUBSTATE APIENTRY Imm32FetchImeSubState(PIME_STATE pState, HKL hKL)
Definition: utils.c:515
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DWORD dwValue
Definition: immdev.h:199

Referenced by Imm32SelectInputContext().

◆ Imm32LoadImeVerInfo()

BOOL APIENTRY Imm32LoadImeVerInfo ( PIMEINFOEX  pImeInfoEx)

Definition at line 763 of file utils.c.

764 {
765  HINSTANCE hinstVersion;
766  BOOL ret = FALSE, bLoaded = FALSE;
768  LPVOID pVerInfo;
769  DWORD cbVerInfo, dwHandle;
770 
771  /* Load version.dll to use the version info API */
773  hinstVersion = GetModuleHandleW(szPath);
774  if (!hinstVersion)
775  {
776  hinstVersion = LoadLibraryW(szPath);
777  if (!hinstVersion)
778  return FALSE;
779 
780  bLoaded = TRUE;
781  }
782 
783 #define GET_FN(name) do { \
784  s_fn##name = (FN_##name)GetProcAddress(hinstVersion, #name); \
785  if (!s_fn##name) goto Quit; \
786 } while (0)
790 #undef GET_FN
791 
792  /* The path of the IME module */
794 
795  cbVerInfo = s_fnGetFileVersionInfoSizeW(szPath, &dwHandle);
796  if (!cbVerInfo)
797  goto Quit;
798 
799  pVerInfo = ImmLocalAlloc(0, cbVerInfo);
800  if (!pVerInfo)
801  goto Quit;
802 
803  /* Load the version info of the IME module */
804  if (s_fnGetFileVersionInfoW(szPath, dwHandle, cbVerInfo, pVerInfo) &&
805  Imm32LoadImeFixedInfo(pImeInfoEx, pVerInfo))
806  {
807  ret = Imm32LoadImeLangAndDesc(pImeInfoEx, pVerInfo);
808  }
809 
810  ImmLocalFree(pVerInfo);
811 
812 Quit:
813  if (bLoaded)
814  FreeLibrary(hinstVersion);
815  return ret;
816 }
#define TRUE
Definition: types.h:120
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define LoadLibraryW(x)
Definition: compat.h:606
static FN_GetFileVersionInfoSizeW s_fnGetFileVersionInfoSizeW
Definition: utils.c:687
#define FreeLibrary(x)
Definition: compat.h:607
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
static BOOL APIENTRY Imm32LoadImeFixedInfo(PIMEINFOEX pInfoEx, LPCVOID pVerInfo)
Definition: utils.c:691
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GET_FN(name)
#define ImmLocalFree(lpData)
Definition: precomp.h:89
int ret
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:611
BOOL Imm32GetSystemLibraryPath(LPWSTR pszPath, DWORD cchPath, LPCWSTR pszFileName)
Definition: utils.c:243
static FN_GetFileVersionInfoW s_fnGetFileVersionInfoW
Definition: utils.c:686
WCHAR wszImeFile[80]
Definition: ntuser.h:1187
LPCWSTR szPath
Definition: env.c:37
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:355
BOOL APIENTRY Imm32LoadImeLangAndDesc(PIMEINFOEX pInfoEx, LPCVOID pVerInfo)
Definition: utils.c:725
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:845
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1049

Referenced by ImmInstallIMEW(), and ImmLoadLayout().

◆ Imm32MakeIMENotify()

BOOL APIENTRY Imm32MakeIMENotify ( HIMC  hIMC,
HWND  hwnd,
DWORD  dwAction,
DWORD_PTR  dwIndex,
DWORD_PTR  dwValue,
DWORD_PTR  dwCommand,
DWORD_PTR  dwData 
)

Definition at line 368 of file utils.c.

370 {
372  HKL hKL;
373  PIMEDPI pImeDpi;
374 
375  if (dwAction)
376  {
378  if (dwThreadId)
379  {
380  /* find keyboard layout and lock it */
382  pImeDpi = ImmLockImeDpi(hKL);
383  if (pImeDpi)
384  {
385  /* do notify */
386  pImeDpi->NotifyIME(hIMC, dwAction, dwIndex, dwValue);
387 
388  ImmUnlockImeDpi(pImeDpi); /* unlock */
389  }
390  }
391  }
392 
393  if (hwnd && dwCommand)
394  SendMessageW(hwnd, WM_IME_NOTIFY, dwCommand, dwData);
395 
396  return TRUE;
397 }
VOID WINAPI ImmUnlockImeDpi(PIMEDPI pImeDpi)
Definition: ime.c:945
#define WM_IME_NOTIFY
Definition: winuser.h:1820
#define TRUE
Definition: types.h:120
static HANDLE ULONG_PTR dwData
Definition: file.c:35
#define DWORD
Definition: nt_native.h:44
DWORD_PTR NTAPI NtUserQueryInputContext(HIMC hIMC, DWORD dwType)
Definition: ime.c:1794
PIMEDPI WINAPI ImmLockImeDpi(HKL hKL)
Definition: ime.c:916
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwThreadId
Definition: fdebug.c:31
UINT_PTR HKL
Definition: msctf.idl:101
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
PKEYBOARD_LAYOUT GetKeyboardLayout()
Definition: utils.c:194
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022

Referenced by ImmSetCandidateWindow(), ImmSetCompositionFontA(), ImmSetCompositionFontW(), ImmSetCompositionWindow(), ImmSetConversionStatus(), ImmSetOpenStatus(), and ImmSetStatusWindowPos().

◆ Imm32ReconvertAnsiFromWide()

DWORD APIENTRY Imm32ReconvertAnsiFromWide ( LPRECONVERTSTRING  pDest,
const RECONVERTSTRING pSrc,
UINT  uCodePage 
)

Definition at line 625 of file utils.c.

626 {
627  DWORD cch0, cch1, cchDest, cbDest;
628  LPCWSTR pchSrc = (LPCWSTR)((LPCSTR)pSrc + pSrc->dwStrOffset);
629  LPSTR pchDest;
630 
631  if (pSrc->dwVersion != 0)
632  return 0;
633 
634  cchDest = WideCharToMultiByte(uCodePage, 0, pchSrc, pSrc->dwStrLen,
635  NULL, 0, NULL, NULL);
636  cbDest = sizeof(RECONVERTSTRING) + (cchDest + 1) * sizeof(CHAR);
637  if (!pDest)
638  return cbDest;
639 
640  if (pDest->dwSize < cbDest)
641  return 0;
642 
643  /* dwSize */
644  pDest->dwSize = cbDest;
645 
646  /* dwVersion */
647  pDest->dwVersion = 0;
648 
649  /* dwStrOffset */
650  pDest->dwStrOffset = sizeof(RECONVERTSTRING);
651 
652  /* dwCompStrOffset */
653  cch1 = pSrc->dwCompStrOffset / sizeof(WCHAR);
654  cch0 = IchAnsiFromWide(cch1, pchSrc, uCodePage);
655  pDest->dwCompStrOffset = cch0 * sizeof(CHAR);
656 
657  /* dwCompStrLen */
658  cch0 = IchAnsiFromWide(cch1 + pSrc->dwCompStrLen, pchSrc, uCodePage);
659  pDest->dwCompStrLen = cch0 * sizeof(CHAR) - pDest->dwCompStrOffset;
660 
661  /* dwTargetStrOffset */
662  cch1 = pSrc->dwTargetStrOffset / sizeof(WCHAR);
663  cch0 = IchAnsiFromWide(cch1, pchSrc, uCodePage);
664  pDest->dwTargetStrOffset = cch0 * sizeof(CHAR);
665 
666  /* dwTargetStrLen */
667  cch0 = IchAnsiFromWide(cch1 + pSrc->dwTargetStrLen, pchSrc, uCodePage);
668  pDest->dwTargetStrLen = cch0 * sizeof(CHAR) - pDest->dwTargetStrOffset;
669 
670  /* dwStrLen */
671  pDest->dwStrLen = cchDest;
672 
673  /* the string */
674  pchDest = (LPSTR)pDest + pDest->dwStrOffset;
675  cchDest = WideCharToMultiByte(uCodePage, 0, pchSrc, pSrc->dwStrLen,
676  pchDest, cchDest, NULL, NULL);
677  pchDest[cchDest] = 0;
678 
679  return cbDest;
680 }
DWORD dwTargetStrOffset
Definition: imm.h:104
#define WideCharToMultiByte
Definition: compat.h:111
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD dwSize
Definition: imm.h:97
struct tagRECONVERTSTRING RECONVERTSTRING
DWORD dwCompStrOffset
Definition: imm.h:102
char * LPSTR
Definition: xmlstorage.h:182
DWORD dwVersion
Definition: imm.h:98
DWORD dwCompStrLen
Definition: imm.h:101
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD dwStrLen
Definition: imm.h:99
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwTargetStrLen
Definition: imm.h:103
DWORD dwStrOffset
Definition: imm.h:100
#define NULL
Definition: types.h:112
LONG APIENTRY IchAnsiFromWide(LONG cchWide, LPCWSTR pchWide, UINT uCodePage)
Definition: utils.c:230
#define CHAR(Char)

Referenced by Imm32ProcessRequest(), and ImmSetCompositionStringAW().

◆ Imm32ReconvertWideFromAnsi()

DWORD APIENTRY Imm32ReconvertWideFromAnsi ( LPRECONVERTSTRING  pDest,
const RECONVERTSTRING pSrc,
UINT  uCodePage 
)

Definition at line 569 of file utils.c.

570 {
571  DWORD cch0, cchDest, cbDest;
572  LPCSTR pchSrc = (LPCSTR)pSrc + pSrc->dwStrOffset;
573  LPWSTR pchDest;
574 
575  if (pSrc->dwVersion != 0)
576  return 0;
577 
578  cchDest = MultiByteToWideChar(uCodePage, MB_PRECOMPOSED, pchSrc, pSrc->dwStrLen,
579  NULL, 0);
580  cbDest = sizeof(RECONVERTSTRING) + (cchDest + 1) * sizeof(WCHAR);
581  if (!pDest)
582  return cbDest;
583 
584  if (pDest->dwSize < cbDest)
585  return 0;
586 
587  /* dwSize */
588  pDest->dwSize = cbDest;
589 
590  /* dwVersion */
591  pDest->dwVersion = 0;
592 
593  /* dwStrOffset */
594  pDest->dwStrOffset = sizeof(RECONVERTSTRING);
595 
596  /* dwCompStrOffset */
597  cch0 = IchWideFromAnsi(pSrc->dwCompStrOffset, pchSrc, uCodePage);
598  pDest->dwCompStrOffset = cch0 * sizeof(WCHAR);
599 
600  /* dwCompStrLen */
601  cch0 = IchWideFromAnsi(pSrc->dwCompStrOffset + pSrc->dwCompStrLen, pchSrc, uCodePage);
602  pDest->dwCompStrLen = (cch0 * sizeof(WCHAR) - pDest->dwCompStrOffset) / sizeof(WCHAR);
603 
604  /* dwTargetStrOffset */
605  cch0 = IchWideFromAnsi(pSrc->dwTargetStrOffset, pchSrc, uCodePage);
606  pDest->dwTargetStrOffset = cch0 * sizeof(WCHAR);
607 
608  /* dwTargetStrLen */
609  cch0 = IchWideFromAnsi(pSrc->dwTargetStrOffset + pSrc->dwTargetStrLen, pchSrc, uCodePage);
610  pDest->dwTargetStrLen = (cch0 * sizeof(WCHAR) - pSrc->dwTargetStrOffset) / sizeof(WCHAR);
611 
612  /* dwStrLen */
613  pDest->dwStrLen = cchDest;
614 
615  /* the string */
616  pchDest = (LPWSTR)((LPBYTE)pDest + pDest->dwStrOffset);
617  cchDest = MultiByteToWideChar(uCodePage, MB_PRECOMPOSED, pchSrc, pSrc->dwStrLen,
618  pchDest, cchDest);
619  pchDest[cchDest] = 0;
620 
621  return cbDest;
622 }
DWORD dwTargetStrOffset
Definition: imm.h:104
DWORD dwSize
Definition: imm.h:97
struct tagRECONVERTSTRING RECONVERTSTRING
DWORD dwCompStrOffset
Definition: imm.h:102
#define MB_PRECOMPOSED
Definition: winnls.h:281
if(dx==0 &&dy==0)
Definition: linetemp.h:174
DWORD dwVersion
Definition: imm.h:98
DWORD dwCompStrLen
Definition: imm.h:101
unsigned char * LPBYTE
Definition: typedefs.h:53
LONG APIENTRY IchWideFromAnsi(LONG cchAnsi, LPCSTR pchAnsi, UINT uCodePage)
Definition: utils.c:210
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD dwStrLen
Definition: imm.h:99
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwTargetStrLen
Definition: imm.h:103
DWORD dwStrOffset
Definition: imm.h:100
#define NULL
Definition: types.h:112
#define MultiByteToWideChar
Definition: compat.h:110
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by Imm32ProcessRequest(), and ImmSetCompositionStringAW().

◆ Imm32SaveImeStateSentence()

BOOL APIENTRY Imm32SaveImeStateSentence ( LPINPUTCONTEXTDX  pIC,
PIME_STATE  pState,
HKL  hKL 
)

Definition at line 548 of file utils.c.

549 {
550  PIME_SUBSTATE pSubState = Imm32FetchImeSubState(pState, hKL);
551  if (pSubState)
552  {
553  pSubState->dwValue = (pIC->fdwSentence & 0xffff0000);
554  return TRUE;
555  }
556  return FALSE;
557 }
PIME_SUBSTATE APIENTRY Imm32FetchImeSubState(PIME_STATE pState, HKL hKL)
Definition: utils.c:515
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DWORD dwValue
Definition: immdev.h:199

Referenced by Imm32SelectInputContext().

◆ Imm32StoreBitmapToBytes()

BOOL Imm32StoreBitmapToBytes ( HBITMAP  hbm,
LPBYTE  pbData,
DWORD  cbDataMax 
)

Definition at line 109 of file utils.c.

110 {
111  HDC hDC;
112  BITMAP bm;
113  DWORD cbBytes, cColors;
114  BITMAPCOREINFO256 bmci;
115  BOOL ret;
116  LPBYTE pb = pbData;
117 
118  *(LPDWORD)pb = 0;
119 
120  if (!GetObject(hbm, sizeof(BITMAP), &bm))
121  return FALSE;
122 
123  ZeroMemory(&bmci, sizeof(bmci));
124  bmci.bmciHeader.bcSize = sizeof(BITMAPCOREHEADER);
125  bmci.bmciHeader.bcWidth = bm.bmWidth;
126  bmci.bmciHeader.bcHeight = bm.bmHeight;
127  bmci.bmciHeader.bcPlanes = 1;
128  bmci.bmciHeader.bcBitCount = bm.bmBitsPixel;
129 
130  switch (bm.bmBitsPixel)
131  {
132  case 1: cColors = 2; break;
133  case 4: cColors = 16; break;
134  case 8: cColors = 256; break;
135  case 24: case 32:
136  cColors = 0;
137  break;
138  default:
139  return FALSE;
140  }
141 
142  cbBytes = sizeof(DWORD);
143  cbBytes += sizeof(BITMAPCOREHEADER);
144  cbBytes += cColors * sizeof(RGBTRIPLE);
145  cbBytes += bm.bmWidthBytes * bm.bmHeight;
146  if (cbBytes > cbDataMax)
147  return FALSE;
148 
150 
151  ret = GetDIBits(hDC, hbm, 0, bm.bmHeight, NULL, (LPBITMAPINFO)&bmci, DIB_RGB_COLORS);
152 
153  if (ret)
154  {
155  *(LPDWORD)pb = cbBytes;
156  pb += sizeof(DWORD);
157 
158  CopyMemory(pb, &bmci.bmciHeader, sizeof(BITMAPCOREHEADER));
159  pb += sizeof(BITMAPCOREHEADER);
160 
161  CopyMemory(pb, &bmci.bmciColors, cColors * sizeof(RGBTRIPLE));
162  pb += cColors * sizeof(RGBTRIPLE);
163 
164  ret = GetDIBits(hDC, hbm, 0, bm.bmHeight, pb, (LPBITMAPINFO)&bmci, DIB_RGB_COLORS);
165  if (!ret)
166  *(LPDWORD)pbData = 0;
167  }
168 
169  DeleteDC(hDC);
170 
171  return ret;
172 }
static HDC
Definition: imagelist.c:92
#define ZeroMemory
Definition: winbase.h:1667
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define DWORD
Definition: nt_native.h:44
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
struct tagRGBTRIPLE RGBTRIPLE
RGBTRIPLE bmciColors[256]
Definition: utils.c:56
#define CopyMemory
Definition: winbase.h:1665
struct tagBITMAPCOREHEADER BITMAPCOREHEADER
unsigned long DWORD
Definition: ntddk_ex.h:95
BITMAPCOREHEADER bmciHeader
Definition: utils.c:55
#define GetObject
Definition: wingdi.h:4468
int ret
#define LPDWORD
Definition: nt_native.h:46
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI DeleteDC(_In_ HDC)
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
Definition: bl.h:1330
#define NULL
Definition: types.h:112
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
#define DIB_RGB_COLORS
Definition: wingdi.h:367
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201

Referenced by ImmPutImeMenuItemsIntoMappedFile().

◆ Imm32StrToUInt()

HRESULT APIENTRY Imm32StrToUInt ( LPCWSTR  pszText,
LPDWORD  pdwValue,
ULONG  nBase 
)

Definition at line 20 of file utils.c.

21 {
25  Status = RtlUnicodeStringToInteger(&UnicodeString, nBase, pdwValue);
26  if (!NT_SUCCESS(Status))
27  return E_FAIL;
28  return S_OK;
29 }
LONG NTSTATUS
Definition: precomp.h:26
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64
#define E_FAIL
Definition: ddrawi.h:102
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define S_OK
Definition: intsafe.h:52
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by Imm32GetImeLayout().

◆ Imm32UIntToStr()

HRESULT APIENTRY Imm32UIntToStr ( DWORD  dwValue,
ULONG  nBase,
LPWSTR  pszBuff,
USHORT  cchBuff 
)

Definition at line 33 of file utils.c.

34 {
37  UnicodeString.Buffer = pszBuff;
38  UnicodeString.MaximumLength = cchBuff * sizeof(WCHAR);
40  if (!NT_SUCCESS(Status))
41  return E_FAIL;
42  return S_OK;
43 }
LONG NTSTATUS
Definition: precomp.h:26
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_opt_ PCUNICODE_STRING UnicodeString
Definition: wdfstring.h:64
#define E_FAIL
Definition: ddrawi.h:102
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define S_OK
Definition: intsafe.h:52

Referenced by Imm32WriteImeLayout(), and ImmInstallIMEW().

◆ Imm32WideFromAnsi()

LPWSTR APIENTRY Imm32WideFromAnsi ( LPCSTR  pszA)

Definition at line 186 of file utils.c.

187 {
188  INT cch = lstrlenA(pszA);
189  LPWSTR pszW = ImmLocalAlloc(0, (cch + 1) * sizeof(WCHAR));
190  if (pszW == NULL)
191  return NULL;
192  cch = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszA, cch, pszW, cch + 1);
193  pszW[cch] = 0;
194  return pszW;
195 }
#define CP_ACP
Definition: compat.h:109
#define MB_PRECOMPOSED
Definition: winnls.h:281
int32_t INT
Definition: typedefs.h:58
__wchar_t WCHAR
Definition: xmlstorage.h:180
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
LPVOID APIENTRY ImmLocalAlloc(DWORD dwFlags, DWORD dwBytes)
Definition: utils.c:355
#define NULL
Definition: types.h:112
#define MultiByteToWideChar
Definition: compat.h:110
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN PCTCH IN DWORD cch
Definition: pager.h:36

Referenced by Imm32EnumWordProcA2W(), ImmConfigureIMEA(), ImmEnumRegisterWordA(), ImmGetConversionListA(), ImmInstallIMEA(), ImmRegisterWordA(), and ImmUnregisterWordA().

◆ Imm32WriteImeLayout()

BOOL APIENTRY Imm32WriteImeLayout ( HKL  hKL,
LPCWSTR  pchFilePart,
LPCWSTR  pszLayout 
)

Definition at line 934 of file utils.c.

935 {
936  UINT iPreload;
937  HKEY hkeyLayouts, hkeyIME, hkeyPreload;
938  WCHAR szImeKey[20], szPreloadNumber[20], szPreloadKey[20], szImeFileName[80];
939  DWORD cbData;
940  LANGID LangID;
941  LONG lError;
942  LPCWSTR pszLayoutFile;
943 
944  /* Open the registry keyboard layouts */
945  lError = RegOpenKeyW(HKEY_LOCAL_MACHINE, REGKEY_KEYBOARD_LAYOUTS, &hkeyLayouts);
946  if (lError != ERROR_SUCCESS)
947  return FALSE;
948 
949  /* Get the IME key from hKL */
950  Imm32UIntToStr((DWORD)(DWORD_PTR)hKL, 16, szImeKey, _countof(szImeKey));
951 
952  /* Create a registry IME key */
953  lError = RegCreateKeyW(hkeyLayouts, szImeKey, &hkeyIME);
954  if (lError != ERROR_SUCCESS)
955  goto Failure;
956 
957  /* Write "Ime File" */
958  cbData = (wcslen(pchFilePart) + 1) * sizeof(WCHAR);
959  lError = RegSetValueExW(hkeyIME, L"Ime File", 0, REG_SZ, (LPBYTE)pchFilePart, cbData);
960  if (lError != ERROR_SUCCESS)
961  goto Failure;
962 
963  /* Write "Layout Text" */
964  cbData = (wcslen(pszLayout) + 1) * sizeof(WCHAR);
965  lError = RegSetValueExW(hkeyIME, L"Layout Text", 0, REG_SZ, (LPBYTE)pszLayout, cbData);
966  if (lError != ERROR_SUCCESS)
967  goto Failure;
968 
969  /* Choose "Layout File" from hKL */
970  LangID = LOWORD(hKL);
971  switch (LOBYTE(LangID))
972  {
973  case LANG_JAPANESE: pszLayoutFile = L"kbdjpn.dll"; break;
974  case LANG_KOREAN: pszLayoutFile = L"kbdkor.dll"; break;
975  default: pszLayoutFile = L"kbdus.dll"; break;
976  }
977  StringCchCopyW(szImeFileName, _countof(szImeFileName), pszLayoutFile);
978 
979  /* Write "Layout File" */
980  cbData = (wcslen(szImeFileName) + 1) * sizeof(WCHAR);
981  lError = RegSetValueExW(hkeyIME, L"Layout File", 0, REG_SZ, (LPBYTE)szImeFileName, cbData);
982  if (lError != ERROR_SUCCESS)
983  goto Failure;
984 
985  RegCloseKey(hkeyIME);
986  RegCloseKey(hkeyLayouts);
987 
988  /* Create "Preload" key */
989  RegCreateKeyW(HKEY_CURRENT_USER, L"Keyboard Layout\\Preload", &hkeyPreload);
990 
991 #define MAX_PRELOAD 0x400
992  for (iPreload = 1; iPreload < MAX_PRELOAD; ++iPreload)
993  {
994  Imm32UIntToStr(iPreload, 10, szPreloadNumber, _countof(szPreloadNumber));
995 
996  /* Load the key of the preload number */
997  cbData = sizeof(szPreloadKey);
998  lError = RegQueryValueExW(hkeyPreload, szPreloadNumber, NULL, NULL,
999  (LPBYTE)szPreloadKey, &cbData);
1000  szPreloadKey[_countof(szPreloadKey) - 1] = 0;
1001 
1002  if (lError != ERROR_SUCCESS || lstrcmpiW(szImeKey, szPreloadKey) == 0)
1003  break; /* Found an empty room or the same key */
1004  }
1005 
1006  if (iPreload >= MAX_PRELOAD) /* Not found */
1007  {
1008  RegCloseKey(hkeyPreload);
1009  return FALSE;
1010  }
1011 #undef MAX_PRELOAD
1012 
1013  /* Write the IME key to the preload number */
1014  cbData = (wcslen(szImeKey) + 1) * sizeof(WCHAR);
1015  lError = RegSetValueExW(hkeyPreload, szPreloadNumber, 0, REG_SZ, (LPBYTE)szImeKey, cbData);
1016  RegCloseKey(hkeyPreload);
1017  return lError == ERROR_SUCCESS;
1018 
1019 Failure:
1020  RegCloseKey(hkeyIME);
1021  RegDeleteKeyW(hkeyLayouts, szImeKey);
1022  RegCloseKey(hkeyLayouts);
1023  return FALSE;
1024 }
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
WORD LANGID
Definition: typedefs.h:81
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
#define LANG_JAPANESE
Definition: nls.h:76
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3291
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4899
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4120
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
#define REGKEY_KEYBOARD_LAYOUTS
Definition: precomp.h:60
HRESULT APIENTRY Imm32UIntToStr(DWORD dwValue, ULONG nBase, LPWSTR pszBuff, USHORT cchBuff)
Definition: utils.c:33
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MAX_PRELOAD
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1199
uint32_t DWORD_PTR
Definition: typedefs.h:65
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define LANG_KOREAN
Definition: nls.h:84
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_writes_opt_ NumCharacters PUSHORT _Inout_ PUSHORT _In_ UCHAR _In_opt_ USHORT LangID
Definition: wdfusb.h:1075
#define LOWORD(l)
Definition: pedump.c:82
#define RegCloseKey(hKey)
Definition: registry.h:47
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by ImmInstallIMEW().

◆ ImmCreateIMCC()

HIMCC WINAPI ImmCreateIMCC ( DWORD  size)

Definition at line 1089 of file utils.c.

1090 {
1091  if (size < sizeof(DWORD))
1092  size = sizeof(DWORD);
1093  return LocalAlloc(LHND, size);
1094 }
#define DWORD
Definition: nt_native.h:44
GLsizeiptr size
Definition: glext.h:5919
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LHND
Definition: winbase.h:379
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373

Referenced by Imm32CreateInputContext(), Imm32SelectInputContext(), START_TEST(), test_ImmDestroyIMCC(), and test_ImmGetIMCCLockCount().

◆ ImmDestroyIMCC()

HIMCC WINAPI ImmDestroyIMCC ( HIMCC  block)

Definition at line 1099 of file utils.c.

1100 {
1101  if (block)
1102  return LocalFree(block);
1103  return NULL;
1104 }
static unsigned int block
Definition: xmlmemory.c:118
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define NULL
Definition: types.h:112

Referenced by Imm32CreateInputContext(), Imm32DestroyInputContext(), Imm32SelectInputContext(), START_TEST(), test_ImmDestroyIMCC(), and test_ImmGetIMCCLockCount().

◆ ImmGetIMCCLockCount()

DWORD WINAPI ImmGetIMCCLockCount ( HIMCC  imcc)

Definition at line 1129 of file utils.c.

1130 {
1131  return LocalFlags(imcc) & LMEM_LOCKCOUNT;
1132 }
#define LMEM_LOCKCOUNT
Definition: winbase.h:376
UINT NTAPI LocalFlags(HLOCAL hMem)
Definition: heapmem.c:1503

Referenced by Imm32SelectInputContext(), START_TEST(), test_ImmDestroyIMCC(), and test_ImmGetIMCCLockCount().

◆ ImmGetIMCCSize()

DWORD WINAPI ImmGetIMCCSize ( HIMCC  imcc)

Definition at line 1147 of file utils.c.

1148 {
1149  if (imcc)
1150  return LocalSize(imcc);
1151  return 0;
1152 }
SIZE_T NTAPI LocalSize(HLOCAL hMem)
Definition: heapmem.c:1777

Referenced by Imm32SelectInputContext(), START_TEST(), Test1(), and test_ImmDestroyIMCC().

◆ ImmGetIMCLockCount()

DWORD WINAPI ImmGetIMCLockCount ( HIMC  hIMC)

Definition at line 1157 of file utils.c.

1158 {
1159  DWORD ret;
1160  HANDLE hInputContext;
1161  PCLIENTIMC pClientImc;
1162 
1163  pClientImc = ImmLockClientImc(hIMC);
1164  if (pClientImc == NULL)
1165  return 0;
1166 
1167  ret = 0;
1168  hInputContext = pClientImc->hInputContext;
1169  if (hInputContext)
1170  ret = (LocalFlags(hInputContext) & LMEM_LOCKCOUNT);
1171 
1172  ImmUnlockClientImc(pClientImc);
1173  return ret;
1174 }
#define LMEM_LOCKCOUNT
Definition: winbase.h:376
PCLIENTIMC WINAPI ImmLockClientImc(HIMC hImc)
Definition: imm.c:901
HANDLE hInputContext
Definition: ntuser.h:1306
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define NULL
Definition: types.h:112
UINT NTAPI LocalFlags(HLOCAL hMem)
Definition: heapmem.c:1503
VOID WINAPI ImmUnlockClientImc(PCLIENTIMC pClientImc)
Definition: imm.c:946

Referenced by test_ImmDestroyContext(), and test_ImmGetIMCLockCount().

◆ ImmIMPGetIMEA()

BOOL WINAPI ImmIMPGetIMEA ( HWND  hWnd,
LPIMEPROA  pImePro 
)

Definition at line 1179 of file utils.c.

1180 {
1181  FIXME("(%p, %p)\n", hWnd, pImePro);
1182  return FALSE;
1183 }
HWND hWnd
Definition: settings.c:17
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111

Referenced by IMPGetIMEA().

◆ ImmIMPGetIMEW()

BOOL WINAPI ImmIMPGetIMEW ( HWND  hWnd,
LPIMEPROW  pImePro 
)

Definition at line 1188 of file utils.c.

1189 {
1190  FIXME("(%p, %p)\n", hWnd, pImePro);
1191  return FALSE;
1192 }
HWND hWnd
Definition: settings.c:17
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111

Referenced by IMPGetIMEW().

◆ ImmIMPQueryIMEA()

BOOL WINAPI ImmIMPQueryIMEA ( LPIMEPROA  pImePro)

Definition at line 1197 of file utils.c.

1198 {
1199  FIXME("(%p)\n", pImePro);
1200  return FALSE;
1201 }
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111

Referenced by IMPQueryIMEA().

◆ ImmIMPQueryIMEW()

BOOL WINAPI ImmIMPQueryIMEW ( LPIMEPROW  pImePro)

Definition at line 1206 of file utils.c.

1207 {
1208  FIXME("(%p)\n", pImePro);
1209  return FALSE;
1210 }
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111

Referenced by IMPQueryIMEW().

◆ ImmIMPSetIMEA()

BOOL WINAPI ImmIMPSetIMEA ( HWND  hWnd,
LPIMEPROA  pImePro 
)

Definition at line 1215 of file utils.c.

1216 {
1217  FIXME("(%p, %p)\n", hWnd, pImePro);
1218  return FALSE;
1219 }
HWND hWnd
Definition: settings.c:17
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111

Referenced by IMPSetIMEA().

◆ ImmIMPSetIMEW()

BOOL WINAPI ImmIMPSetIMEW ( HWND  hWnd,
LPIMEPROW  pImePro 
)

Definition at line 1224 of file utils.c.

1225 {
1226  FIXME("(%p, %p)\n", hWnd, pImePro);
1227  return FALSE;
1228 }
HWND hWnd
Definition: settings.c:17
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111

Referenced by IMPSetIMEW().

◆ ImmLocalAlloc()

◆ ImmLockIMCC()

◆ ImmReSizeIMCC()

HIMCC WINAPI ImmReSizeIMCC ( HIMCC  imcc,
DWORD  size 
)

Definition at line 1137 of file utils.c.

1138 {
1139  if (!imcc)
1140  return NULL;
1141  return LocalReAlloc(imcc, size, LHND);
1142 }
GLsizeiptr size
Definition: glext.h:5919
HLOCAL NTAPI LocalReAlloc(HLOCAL hMem, SIZE_T dwBytes, UINT uFlags)
Definition: heapmem.c:1608
#define LHND
Definition: winbase.h:379
#define NULL
Definition: types.h:112

Referenced by Imm32SelectInputContext(), and test_ImmMessages().

◆ ImmUnlockIMCC()

◆ LogFontAnsiToWide()

VOID APIENTRY LogFontAnsiToWide ( const LOGFONTA plfA,
LPLOGFONTW  plfW 
)

Definition at line 253 of file utils.c.

254 {
255  size_t cch;
256  RtlCopyMemory(plfW, plfA, offsetof(LOGFONTA, lfFaceName));
259  plfW->lfFaceName, _countof(plfW->lfFaceName));
260  if (cch > _countof(plfW->lfFaceName) - 1)
261  cch = _countof(plfW->lfFaceName) - 1;
262  plfW->lfFaceName[cch] = 0;
263 }
#define CP_ACP
Definition: compat.h:109
#define MB_PRECOMPOSED
Definition: winnls.h:281
int32_t INT
Definition: typedefs.h:58
#define offsetof(TYPE, MEMBER)
#define _countof(array)
Definition: sndvol32.h:68
STRSAFEAPI StringCchLengthA(STRSAFE_LPCSTR psz, size_t cchMax, size_t *pcchLength)
Definition: strsafe.h:832
#define MultiByteToWideChar
Definition: compat.h:110
CHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:55
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
WCHAR lfFaceName[LF_FACESIZE]
Definition: wingdi.h:1910
IN PCTCH IN DWORD cch
Definition: pager.h:36

Referenced by Imm32ProcessRequest(), Imm32SelectInputContext(), ImmGetCompositionFontW(), and ImmSetCompositionFontA().

◆ LogFontWideToAnsi()

VOID APIENTRY LogFontWideToAnsi ( const LOGFONTW plfW,
LPLOGFONTA  plfA 
)

Definition at line 266 of file utils.c.

267 {
268  size_t cch;
269  RtlCopyMemory(plfA, plfW, offsetof(LOGFONTW, lfFaceName));
272  plfA->lfFaceName, _countof(plfA->lfFaceName), NULL, NULL);
273  if (cch > _countof(plfA->lfFaceName) - 1)
274  cch = _countof(plfA->lfFaceName) - 1;
275  plfA->lfFaceName[cch] = 0;
276 }
#define WideCharToMultiByte
Definition: compat.h:111
#define CP_ACP
Definition: compat.h:109
int32_t INT
Definition: typedefs.h:58
CHAR lfFaceName[LF_FACESIZE]
Definition: wingdi.h:1894
#define offsetof(TYPE, MEMBER)
#define _countof(array)
Definition: sndvol32.h:68
#define NULL
Definition: types.h:112
STRSAFEAPI StringCchLengthW(STRSAFE_LPCWSTR psz, size_t cchMax, size_t *pcchLength)
Definition: strsafe.h:842
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
IN PCTCH IN DWORD cch
Definition: pager.h:36

Referenced by Imm32ProcessRequest(), Imm32SelectInputContext(), ImmGetCompositionFontA(), and ImmSetCompositionFontW().

◆ ValidateHandle()

LPVOID FASTCALL ValidateHandle ( HANDLE  hObject,
UINT  uType 
)

Definition at line 328 of file utils.c.

329 {
330  LPVOID pvObj = ValidateHandleNoErr(hObject, uType);
331  if (pvObj)
332  return pvObj;
333 
334  if (uType == TYPE_WINDOW)
336  else
338  return NULL;
339 }
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
LPVOID FASTCALL ValidateHandleNoErr(HANDLE hObject, UINT uType)
Definition: utils.c:292
#define ERROR_INVALID_WINDOW_HANDLE
Definition: winerror.h:881
#define SetLastError(x)
Definition: compat.h:611
#define NULL
Definition: types.h:112

◆ ValidateHandleNoErr()

LPVOID FASTCALL ValidateHandleNoErr ( HANDLE  hObject,
UINT  uType 
)

Definition at line 292 of file utils.c.

293 {
294  UINT index;
298  LPVOID ptr;
299 
300  if (!NtUserValidateHandleSecure(hObject))
301  return NULL;
302 
303  ht = gSharedInfo.aheList; /* handle table */
304  ASSERT(ht);
305  /* ReactOS-Specific! */
308 
309  index = (LOWORD(hObject) - FIRST_USER_HANDLE) >> 1;
310  if ((INT)index < 0 || ht->nb_handles <= index || he[index].type != uType)
311  return NULL;
312 
313  if (he[index].flags & HANDLEENTRY_DESTROY)
314  return NULL;
315 
316  generation = HIWORD(hObject);
317  if (generation != he[index].generation && generation && generation != 0xFFFF)
318  return NULL;
319 
320  ptr = he[index].ptr;
321  if (ptr)
323 
324  return ptr;
325 }
unsigned char type
Definition: ntuser.h:25
#define FIRST_USER_HANDLE
Definition: ntuser.h:10
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
static PVOID ptr
Definition: dispmode.c:27
GLuint index
Definition: glext.h:6031
BOOL NTAPI NtUserValidateHandleSecure(HANDLE hHdl)
Definition: object.c:792
Definition: ntuser.h:16
struct _USER_HANDLE_ENTRY * PUSER_HANDLE_ENTRY
#define ASSERT(a)
Definition: mode.c:44
unsigned short WORD
Definition: ntddk_ex.h:93
GLbitfield flags
Definition: glext.h:7161
SHAREDINFO gSharedInfo
Definition: imm.c:18
#define index(s, c)
Definition: various.h:29
ULONG_PTR ulSharedDelta
Definition: ntuser.h:1100
#define HANDLEENTRY_DESTROY
Definition: ntuser.h:13
_In_ uint64_t _In_ uint64_t _In_ uint64_t generation
Definition: btrfs.c:2995
static const struct newhuff ht[]
Definition: huffman.h:296
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
static PVOID FASTCALL DesktopPtrToUser(PVOID ptr)
Definition: utils.c:278
#define HIWORD(l)
Definition: typedefs.h:247
void * ptr
Definition: ntuser.h:18
#define LOWORD(l)
Definition: pedump.c:82
PVOID aheList
Definition: ntuser.h:1098

Referenced by ValidateHandle().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( imm  )

Variable Documentation

◆ ghImmHeap

HANDLE ghImmHeap = NULL

Definition at line 16 of file utils.c.

Referenced by ImmLocalAlloc().

◆ s_fnGetFileVersionInfoSizeW

FN_GetFileVersionInfoSizeW s_fnGetFileVersionInfoSizeW = NULL
static

Definition at line 687 of file utils.c.

Referenced by Imm32LoadImeVerInfo().

◆ s_fnGetFileVersionInfoW

FN_GetFileVersionInfoW s_fnGetFileVersionInfoW = NULL
static

Definition at line 686 of file utils.c.

Referenced by Imm32LoadImeVerInfo().

◆ s_fnVerQueryValueW

FN_VerQueryValueW s_fnVerQueryValueW = NULL
static

Definition at line 688 of file utils.c.

Referenced by Imm32GetVerInfoValue(), Imm32LoadImeFixedInfo(), and Imm32LoadImeLangAndDesc().