using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// Methods, constants, structures and interfaces for Microsoft Text Services Framework.
public static partial class MSCTF
{
/// CLSID_SapiLayr
public static readonly Guid CLSID_SapiLayr = new(0xdcbd6fa8, 0x032f, 0x11d3, 0xb5, 0xb1, 0x00, 0xc0, 0x4f, 0xc3, 0x24, 0xa1);
private const string Lib_Msctf = "msctf.dll";
private const string Lib_msimtf = "msimtf.dll";
/// Flags for DoMsCtfMonitor()
[PInvokeData("msctfmonitorapi.h", MSDNShortId = "NF:msctfmonitorapi.InitLocalMsCtfMonitor")]
[Flags]
public enum DCM_FLAGS : uint
{
/// Undocumented.
DCM_FLAGS_TASKENG = 0x00000001,
/// Undocumented.
DCM_FLAGS_CTFMON = 0x00000002,
/// Undocumented.
DCM_FLAGS_LOCALTHREADTSF = 0x00000004,
}
/// Flags for InitLocalMsCtfMonitor()
[PInvokeData("msctfmonitorapi.h", MSDNShortId = "NF:msctfmonitorapi.InitLocalMsCtfMonitor")]
[Flags]
public enum ILMCM : uint
{
///
/// InitLocalMsCtfMonitor forcefully checks the available keyboard layout or text service. If there is no secondary keyboard
/// layout or text services, it does not initialize TextServicesFramework on the desktop.
///
ILMCM_CHECKLAYOUTANDTIPENABLED = 0x00001,
/// Starting with Windows 8: A local language bar is not started for the current desktop.
ILMCM_LANGUAGEBAROFF = 0x00002
}
/// Bitfield options for InstallLayoutOrTip.
[PInvokeData("")]
[Flags]
public enum ILOT
{
/// Same as ILOT_DISABLED.
ILOT_UNINSTALL = 0x00000001,
/// Sets the specified layout or tip as a default item.
ILOT_DEFPROFILE = 0x00000002,
/// Changes the setting of .Default.
ILOT_DEFUSER4 = 0x00000004,
/// Unused.
ILOT_SYSLOCALE = 0x00000008,
/// Unused.
ILOT_NOLOCALETOENUMERATE = 0x00000010,
/// The setting is saved but is not applied to the current session.
ILOT_NOAPPLYTOCURRENTSESSION = 0x00000020,
/// Disables all of the current keyboard layouts and text services.
ILOT_CLEANINSTALL = 0x00000040,
/// Disables the specified keyboard layout and text service.
ILOT_DISABLED = 0x00000080,
}
/// Flags for
public enum LOT
{
/// If this is on, this is a default item.
LOT_DEFAULT = 0x0001,
/// if this is on, this is not enabled.
LOT_DISABLED = 0x0002,
}
/// Flags for
public enum LOTP
{
///
LOTP_INPUTPROCESSOR = 1,
///
LOTP_KEYBOARDLAYOUT = 2
}
/// Flags for SetDefaultLayoutOrTip().
[PInvokeData("")]
[Flags]
public enum SDLOT : uint
{
///
/// Stores the setting in the registry but dose not update the runtime keyboard setting of the current session. If the
/// alternative registry path is set in SetDefaultLayoutOrTipUserReg, this flag should be set.
///
SDLOT_NOAPPLYTOCURRENTSESSION = 0x00000001,
/// Applies the setting immediately on the current thread.
SDLOT_APPLYTOCURRENTTHREAD = 0x00000002,
}
/// Undocumented.
///
///
///
[PInvokeData("msctfmonitorapi.h", MSDNShortId = "NF:msctfmonitorapi.InitLocalMsCtfMonitor")]
[DllImport(Lib_Msctf, SetLastError = true, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DoMsCtfMonitor(DCM_FLAGS dwFlags, HEVENT hEventForServiceStop);
/// Enumerates all enabled keyboard layouts or text services of the specified user setting.
/// The registry path of the user. If this parameter is NULL, HKEY_CURRENT_USER is used.
///
/// The registry path of the system. If this parameter is NULL, HKEY_LOCAL_MACHINE\System is used.
///
///
/// The registry path of the software. If this parameter is NULL, HKEY_LOCAL_MACHINE\Software is used.
///
/// Pointer to the buffer that receives the LAYOUTORTIPPROFILE array.
/// The length of the buffer pointed to by pLayoutOrTipProfile.
///
///
/// If pLayoutOrTipProfile is NULL, the number of keyboard items that are enabled in the user setting; otherwise, the number
/// of keyboard items that are copied into pLayoutOrTipProfile.
///
///
/// For Input Method Editor (IME) languages, all IMEs are returned, even when only one IME is enabled. For example, if a user has
/// the CHT New Quick IME enabled, the EnumEnabledLayoutOrTip function returns all 5 CHT IMEs.
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/enumenabledlayoutortip UINT EnumEnabledLayoutOrTip( _In_opt_ LPCWSTR
// pszUserReg, _In_opt_ LPCWSTR pszSystemReg, _In_opt_ LPCWSTR pszSoftwareReg, _Out_ LAYOUTORTIPPROFILE *pLayoutOrTipProfile, _In_
// UINT uBufLength );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
public static extern uint EnumEnabledLayoutOrTip([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszUserReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSystemReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSoftwareReg, out LAYOUTORTIPPROFILE pLayoutOrTipProfile,
uint uBufLength);
/// Enumerates the installed keyboard layouts and text services of the setup UI or OOBE.
/// The language id of the item to be enumerated.
///
/// Pointer to the buffer that receives the array of LAYOUTORTIP structures. This can be NULL to get the number of items.
///
/// The length of the buffer pointed to by pLayoutOrTip. This is ignored if pLayoutOrTip is NULL.
/// Not used. This must be zero.
///
/// If pLayoutOrTip is NULL, the number of keyboard items that are registered in System; otherwise, the number of keyboard
/// items that are copied into pLayoutOrTip.
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/enumlayoutortipforsetup UINT CALLBACK EnumLayoutOrTipForSetup( _In_ LANGID
// langid, _Out_ LAYOUTORTIP *pLayoutOrTip, _In_ UINT uBufLength, _In_ DWORD dwFlags );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
public static extern uint EnumLayoutOrTipForSetup([In] LANGID langid, out LAYOUTORTIP pLayoutOrTip, uint uBufLength, uint dwFlags = 0);
///
/// The InitLocalMsCtfMonitor function initializes TextServicesFramework on the current desktop and prepares the floating
/// language bar, if necessary. This function must be called on the app's desktop.
///
///
/// This is a combination of the following flags:
///
///
/// Value
/// Meaning
///
/// -
/// ILMCM_CHECKLAYOUTANDTIPENABLED
///
/// InitLocalMsCtfMonitor forcefully checks the available keyboard layout or text service. If there is no secondary keyboard layout
/// or text services, it does not initialize TextServicesFramework on the desktop.
///
///
/// -
/// ILMCM_LANGUAGEBAROFF
/// Starting with Windows 8: A local language bar is not started for the current desktop.
///
///
///
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
///
///
///
/// If this function was successful, UninitLocalMsCtfMonitor needs to be called before the caller thread is terminated or the
/// desktop is switched.
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctfmonitorapi/nf-msctfmonitorapi-initlocalmsctfmonitor HRESULT
// InitLocalMsCtfMonitor( DWORD dwFlags );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctfmonitorapi.h", MSDNShortId = "NF:msctfmonitorapi.InitLocalMsCtfMonitor")]
public static extern HRESULT InitLocalMsCtfMonitor(ILMCM dwFlags);
/// Enables the specified keyboard layouts or text services.
/// A string that represents the keyboard layout list or text services profile list.
///
/// A bitfield.
///
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// The function was successful.
///
/// -
/// FALSE
/// An unspecified error occurred.
///
///
///
///
/// The string format of the layout list is:
/// <LangID 1>:<KLID 1>;[...:
/// The string format of the text service profile list is:
/// <LangID 1>:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx};
/// The following is an example of a value for the psz parameter:
///
/// "0x0407:0x00000407" "0x0407:0x00000407;0x040C:0x0000040C" "0x0407:0x00000407;0x0412:{A028AE76-01B1-46C2-99C4-ACD9858AE02F}{B5FE1F02-D5F2-4445-9C03-C568F23C99A1};0x040C:0x0000040C"
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/installlayoutortip BOOL CALLBACK InstallLayoutOrTip( _In_ LPCWSTR psz, _In_
// DWORD dwFlags );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InstallLayoutOrTip([In, MarshalAs(UnmanagedType.LPWStr)] string psz, [In] ILOT dwFlags);
/// Enables the specified keyboard layouts or text services for the specified user.
/// The registry path of the user. If this parameter is NULL, HKEY_CURRENT_USER is used.
///
/// The registry path of the system. If this parameter is NULL, HKEY_LOCAL_MACHINE\System is used.
///
///
/// The registry path of the software. If this parameter is NULL, HKEY_LOCAL_MACHINE\Software is used.
///
/// A string that represents the keyboard layout list or text services profile list.
///
/// A bitfield that specifies the following flags.
///
///
/// Value
/// Meaning
///
/// -
/// ILOT_UNINSTALL 0x00000001
/// Same as ILOT_DISABLED.
///
/// -
/// ILOT_DEFPROFILE 0x00000002
/// Sets the specified layout or tip as a default item.
///
/// -
/// ILOT_NOAPPLYTOCURRENTSESSION 0x00000020
/// The setting is saved but is not applied to the current session.
///
/// -
/// ILOT_CLEANINSTALL 0x00000040
/// Disables all of the current keyboard layouts and text services.
///
/// -
/// ILOT_DISABLED 0x00000080
/// Disables the specified keyboard layout and text service.
///
///
///
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// The function was successful.
///
/// -
/// FASE
/// An unspecified error occurred.
///
///
///
///
/// The string format of the layout list is:
/// <LangID 1>:<KLID 1>;[...:
/// The string format of the text service profile list is:
/// <LangID 1>:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx};
/// The following is an example of a value for the psz parameter:
///
/// "0x0407:0x00000407" "0x0407:0x00000407;0x040C:0x0000040C" "0x0407:0x00000407;0x0412:{A028AE76-01B1-46C2-99C4-ACD9858AE02F}{B5FE1F02-D5F2-4445-9C03-C568F23C99A1};0x040C:0x0000040C"
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/installlayoutortipuserreg BOOL CALLBACK InstallLayoutOrTipUserReg( _In_opt_
// LPCWSTR pszUserReg, _In_opt_ LPCWSTR pszSystemReg, _In_opt_ LPCWSTR pszSoftwareReg, _In_ LPCWSTR psz, _In_ DWORD dwFlags );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InstallLayoutOrTipUserReg([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszUserReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSystemReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSoftwareReg,
[In, MarshalAs(UnmanagedType.LPWStr)] string psz, [In] ILOT dwFlags);
/// The MsimtfIsWindowFiltered function tests if the given window is filtered by AIMM (Active Input Method Manager).
/// A window handle to be tested.
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// If this window is filtered by Active Input Method Manager.
///
/// -
/// FALSE
/// If this window is not filtered by Active Input Method Manager.
///
///
///
/// A window can be filtered by IActiveIMMApp::FilterClientWindows.
// https://docs.microsoft.com/en-us/windows/win32/tsf/msimtfiswindowfiltered BOOL CALLBACK MsimtfIsWindowFiltered( _In_ HWND hwnd );
[DllImport(Lib_msimtf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MsimtfIsWindowFiltered([In] HWND hwnd);
/// Queries the specified string which represents the format of a keyboard layout list or text services profile list.
/// A string that represents a keyboard layout list or a text services profile list.
/// This must be 0.
///
/// This function can return one of these values.
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// All layouts or profiles defined in psz are valid.
///
/// -
/// E_INVALIDARG
/// One or more of the layouts or profiles defined in psz are invalid.
///
///
///
///
/// The string format of the layout list is:
/// <LangID 1>:<KLID 1>;[...:
/// The string format of the text service profile list is:
/// <LangID 1>:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx};
/// The following is an example of a value for the psz parameter:
///
/// "0x0407:0x00000407" "0x0407:0x00000407;0x040C:0x0000040C" "0x0407:0x00000407;0x0412:{A028AE76-01B1-46C2-99C4-ACD9858AE02F}{B5FE1F02-D5F2-4445-9C03-C568F23C99A1};0x040C:0x0000040C"
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/querylayoutortipstring HRESULT CALLBACK QueryLayoutOrTipString( _In_ LPCWSTR
// psz, _In_ DWORD dwFlags );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
public static extern HRESULT QueryLayoutOrTipString([In, MarshalAs(UnmanagedType.LPWStr)] string psz, uint dwFlags = 0);
///
/// Queries the specified string which represents the format of a keyboard layout list or text services profile list of the
/// specified registry path.
///
/// The registry path of the user. If this parameter is NULL, HKEY_CURRENT_USER is used.
///
/// The registry path of the system. If this parameter is NULL, HKEY_LOCAL_MACHINE\System is used.
///
///
/// The registry path of the software. If this parameter is NULL, HKEY_LOCAL_MACHINE\Software is used.
///
/// A string that represents a keyboard layout list or a text services profile list.
/// This must be 0.
///
/// This function can return one of these values.
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// All layouts or profiles defined in psz are valid.
///
/// -
/// E_INVALIDARG
/// One or more of the layouts or profiles defined in psz are invalid.
///
///
///
///
/// The string format of the layout list is:
/// <LangID 1>:<KLID 1>;[...:
/// The string format of the text service profile list is:
/// <LangID 1>:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx};
/// The following is an example of a value for the psz parameter:
///
/// "0x0407:0x00000407" "0x0407:0x00000407;0x040C:0x0000040C" "0x0407:0x00000407;0x0412:{A028AE76-01B1-46C2-99C4-ACD9858AE02F}{B5FE1F02-D5F2-4445-9C03-C568F23C99A1};0x040C:0x0000040C"
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/querylayoutortipstringuserreg HRESULT CALLBACK QueryLayoutOrTipStringUserReg(
// _In_ LPCWSTR pszUserReg, _In_ LPCWSTR pszSystemReg, _In_ LPCWSTR pszSoftwareReg, _In_ LPCWSTR psz, _In_ DWORD dwFlags );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
public static extern HRESULT QueryLayoutOrTipStringUserReg([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszUserReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSystemReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSoftwareReg,
[In, MarshalAs(UnmanagedType.LPWStr)] string psz, [In] uint dwFlags = 0);
/// Applies the user keyboard layout and text service setting to the default user hive.
///
/// The parent window for the warning dialog box. The warning dialog box is not always shown and appears appropriately. If this
/// parameter is NULL, the warning dialog box will not be shown.
///
/// The root registry key of the user setting to be copied.
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// The function was successful.
///
/// -
/// FALSE
/// An unspecified error occurred.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/savedefaultuserinputsettings BOOL CALLBACK SaveDefaultUserInputSettings( _In_
// HWND hwndParent, _In_ HKEY hSourceRegKey );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SaveDefaultUserInputSettings([In] HWND hwndParent, [In] HKEY hSourceRegKey);
/// Applies the user keyboard layout and text service setting to the system accounts hive.
///
/// The parent window for the warning dialog box. The warning dialog box is not always shown and appears appropriately. If this
/// parameter is NULL, the warning dialog box will not be shown.
///
/// The root registry key of the user setting to be copied.
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// The function was successful.
///
/// -
/// FALSE
/// An unspecified error occurred.
///
///
///
/// The system account hive is HKEY_USERS\.DEFAULT, HKEY_USERS\S-1-5-19, and HKEY_USERS\S-1-5-20.
// https://docs.microsoft.com/en-us/windows/win32/tsf/savesystemacctinputsettings BOOL CALLBACK SaveSystemAcctInputSettings( _In_
// HWND hwndParent, _In_ HKEY hSourceRegKey );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SaveSystemAcctInputSettings([In] HWND hwndParent, [In] HKEY hSourceRegKey);
/// Sets the specified keyboard layout or a text service as the default input item of the current user.
/// A string that represents a keyboard layout list or a text services profile list.
///
/// A bitfield that specifies the following flags.
///
///
/// Value
/// Meaning
///
/// -
/// SDLOT_NOAPPLYTOCURRENTSESSION 0x00000001
///
/// Stores the setting in the registry but dose not update the runtime keyboard setting of the current session. If the alternative
/// registry path is set in SetDefaultLayoutOrTipUserReg, this flag should be set.
///
///
/// -
/// SDLOT_APPLYTOCURRENTTHREAD 0x00000002
/// Applies the setting immediately on the current thread.
///
///
///
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// The function was successful.
///
/// -
/// FALSE
/// An unspecified error occurred.
///
///
///
///
/// The string format of the layout list is:
/// <LangID 1>:<KLID 1>;[...:
/// The string format of the text service profile list is:
/// <LangID 1>:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx};
/// The following is an example of a value for the psz parameter:
///
/// "0x0407:0x00000407" "0x0407:0x00000407;0x040C:0x0000040C" "0x0407:0x00000407;0x0412:{A028AE76-01B1-46C2-99C4-ACD9858AE02F}{B5FE1F02-D5F2-4445-9C03-C568F23C99A1};0x040C:0x0000040C"
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/setdefaultlayoutortip BOOL CALLBACK SetDefaultLayoutOrTip( _In_ LPCWSTR psz,
// _In_ LPCWSTR psz DWORD dwFlags );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetDefaultLayoutOrTip([In, MarshalAs(UnmanagedType.LPWStr)] string psz, SDLOT dwFlags);
/// Sets the specified keyboard layout or a text service as a default input item of the user registry.
/// The registry path of the user. If this parameter is NULL, HKEY_CURRENT_USER is used.
///
/// The registry path of the system. If this parameter is NULL, HKEY_LOCAL_MACHINE\System is used.
///
///
/// The registry path of the software. If this parameter is NULL, HKEY_LOCAL_MACHINE\Software is used.
///
/// A string that represents the keyboard layout list or text services profile list.
///
/// A bitfield that specifies the following flags:
///
///
/// Value
/// Meaning
///
/// -
/// SDLOT_NOAPPLYTOCURRENTSESSION 0x00000001
///
/// Stores the setting in the registry but dose not update the runtime keyboard setting of the current session. If the alternative
/// registry path is set in SetDefaultLayoutOrTipUserReg, this flag should be set.
///
///
/// -
/// SDLOT_APPLYTOCURRENTTHREAD 0x00000002
/// Applies the setting immediately on the current thread.
///
///
///
///
///
///
/// Return code
/// Description
///
/// -
/// TRUE
/// The function was successful.
///
/// -
/// FALSE
/// An unspecified error occurred.
///
///
///
///
/// The string format of the layout list is:
/// <LangID 1>:<KLID 1>;[...:
/// The string format of the text service profile list is:
/// <LangID 1>:{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx};
/// The following is an example of a value for the psz parameter:
///
/// "0x0407:0x00000407" "0x0407:0x00000407;0x040C:0x0000040C" "0x0407:0x00000407;0x0412:{A028AE76-01B1-46C2-99C4-ACD9858AE02F}{B5FE1F02-D5F2-4445-9C03-C568F23C99A1};0x040C:0x0000040C"
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/setdefaultlayoutortipuserreg BOOL CALLBACK SetDefaultLayoutOrTipUserReg(
// _In_opt_ LPCWSTR pszUserReg, _In_opt_ LPCWSTR pszSystemReg, _In_opt_ LPCWSTR pszSoftwareReg, _In_ LPCWSTR psz, _In_ DWORD dwFlags );
[DllImport(Lib_input, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetDefaultLayoutOrTipUserReg([In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszUserReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSystemReg,
[In, Optional, MarshalAs(UnmanagedType.LPWStr)] string pszSoftwareReg,
[In, MarshalAs(UnmanagedType.LPWStr)] string psz, [In] SDLOT dwFlags);
///
/// The TF_CreateCategoryMgr function creates a category manager object without having to initialize COM. Usage must be done
/// carefully because the calling thread must maintain the reference count on an object that is owned by MSCTF.DLL.
///
/// Pointer to ITFCategoryMgr interface pointer that receives the category manager object.
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-tf_createcategorymgr HRESULT TF_CreateCategoryMgr(
// ITfCategoryMgr **ppcat );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctf.h", MSDNShortId = "NF:msctf.TF_CreateCategoryMgr")]
public static extern HRESULT TF_CreateCategoryMgr(out ITfCategoryMgr ppcat);
///
///
/// The TF_CreateDisplayAttributeMgr function is used to create a display attribute manager object without having to
/// initialize COM. Usage of this method is not recommended, because the calling process must maintain a proper reference count on
/// an object that is owned by Msctf.dll.
///
///
/// It is instead recommended that display attribute manager objects be created using CoCreateInstance , as demonstrated in ITfDisplayAttributeMgr.
///
///
///
/// Pointer to an ITfDisplayAttributeMgr interface pointer that receives the display attribute manager object.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
/// -
/// E_INVALIDARG
/// ppdam is invalid.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-tf_createdisplayattributemgr HRESULT
// TF_CreateDisplayAttributeMgr( ITfDisplayAttributeMgr **ppdam );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctf.h", MSDNShortId = "NF:msctf.TF_CreateDisplayAttributeMgr")]
public static extern HRESULT TF_CreateDisplayAttributeMgr(out ITfDisplayAttributeMgr ppdam);
///
///
/// The TF_CreateInputProcessorProfiles function is used to create a input processor profile object without having to
/// initialize COM. Usage of this method is not recommended, because the calling process must maintain a proper reference count on
/// an object that is owned by Msctf.dll.
///
///
/// It is instead recommended that input processor profile objects be created using CoCreateInstance , as demonstrated in ITfInputProcessorProfiles.
///
///
///
/// Pointer to an ITfInputProcessorProfiles interface pointer that receives the input processor profile object.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
/// -
/// E_INVALIDARG
/// ppipr is invalid.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-tf_createinputprocessorprofiles HRESULT
// TF_CreateInputProcessorProfiles( ITfInputProcessorProfiles **ppipr );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctf.h", MSDNShortId = "NF:msctf.TF_CreateInputProcessorProfiles")]
public static extern HRESULT TF_CreateInputProcessorProfiles(out ITfInputProcessorProfiles ppipr);
///
///
/// The TF_CreateLangBarItemMgr function is used to create a language bar item manager object without having to initialize
/// COM. Usage of this method is not recommended, because the calling process must maintain a proper reference count on an object
/// that is owned by Msctf.dll.
///
///
/// It is instead recommended that language bar item manager objects be created using CoCreateInstance , as demonstrated in ITfLangBarItemMgr.
///
///
/// Pointer to an ITfLangBarItemMgr interface pointer that receives the language bar item manager object.
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
/// -
/// E_INVALIDARG
/// pplbim is invalid.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-tf_createlangbaritemmgr HRESULT TF_CreateLangBarItemMgr(
// ITfLangBarItemMgr **pplbim );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctf.h", MSDNShortId = "NF:msctf.TF_CreateLangBarItemMgr")]
public static extern HRESULT TF_CreateLangBarItemMgr(out ITfLangBarItemMgr pplbim);
///
///
/// The TF_CreateLangBarMgr function creates a language bar manager object without having to initialize COM. Usage of this
/// method is not recommended, because the calling process must maintain a proper reference count on an object that is owned by Msctf.dll.
///
/// It is instead recommended that language bar manager objects be created using CoCreateInstance , as demonstrated in ITfLangBarMgr.
///
/// Pointer to an ITfLangBarMgr interface pointer that receives the language bar manager object.
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
/// -
/// E_INVALIDARG
/// pppbm is invalid.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-tf_createlangbarmgr HRESULT TF_CreateLangBarMgr( ITfLangBarMgr
// **pppbm );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctf.h", MSDNShortId = "NF:msctf.TF_CreateLangBarMgr")]
public static extern HRESULT TF_CreateLangBarMgr(out ITfLangBarMgr pppbm);
///
///
/// The TF_CreateThreadMgr function creates a thread manager object without having to initialize COM. Usage of this method is
/// not recommended, because the calling process must maintain a proper reference count on an object that is owned by Msctf.dll.
///
/// It is instead recommended that thread manager objects be created using CoCreateInstance , as demonstrated in ITfThreadMgr.
///
/// Pointer to an ITfThreadMgr interface pointer that receives the thread manager object.
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
/// -
/// E_INVALIDARG
/// pptim is invalid.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-tf_createthreadmgr HRESULT TF_CreateThreadMgr( ITfThreadMgr
// **pptim );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctf.h", MSDNShortId = "NF:msctf.TF_CreateThreadMgr")]
public static extern HRESULT TF_CreateThreadMgr(out ITfThreadMgr pptim);
///
/// The TF_GetThreadMgr function obtains a copy of a thread manager object previously created within the calling thread.
///
///
/// Pointer to an ITfThreadMgr interface pointer that receives the thread manager object. This receives NULL if no thread
/// manager is created within the calling thread.
///
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful. pptim will be NULL if no thread manager is created within the calling thread.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
///
///
///
///
/// If no thread manager is created within the calling thread, this function will set pptim to NULL and return S_OK.
/// Therefore, it is necessary to verify that the function succeeded and that pptim is not NULL before using pptim.
///
/// Examples
///
/// There is no import library available that defines this function, so it is necessary to manually obtain a pointer to this
/// function using LoadLibrary and GetProcAddress. The following code example demonstrates how to accomplish this.
///
///
/// The following example demonstrates a function that will attempt to obtain a copy of a previously created thread manager object.
/// If no thread manager object exists within the calling thread, the function will create one.
///
/// Note
///
/// Using LoadLibrary incorrectly can compromise the security of your application by loading the wrong DLL. Refer to the
/// LoadLibrary documentation for information on how to correctly load DLLs with different versions of Windows.
///
///
/// typedef HRESULT (WINAPI *PTF_GETTHREADMGR)(ITfThreadMgr **pptim); HRESULT GetThreadMgr(ITfThreadMgr **pptm) { HRESULT hr = E_FAIL; HMODULE hMSCTF = LoadLibrary(TEXT("msctf.dll")); ITfThreadMgr *pThreadMgr = NULL; if(hMSCTF == NULL) { //Error loading module -- fail as securely as possible } else { PTF_GETTHREADMGR pfnGetThreadMgr; pfnGetThreadMgr = (PTF_GETTHREADMGR)GetProcAddress(hMSCTF, "TF_GetThreadMgr"); if(pfnGetThreadMgr) { hr = (*pfnGetThreadMgr)(&pThreadMgr); } FreeLibrary(hMSCTF); } //If no object could be obtained, try to create one. if(NULL == pThreadMgr) { //CoInitialize or OleInitialize must already have been called. hr = CoCreateInstance( CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, (void**)&pThreadMgr); } *pptm = pThreadMgr; return hr; }
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctf/nf-msctf-tf_getthreadmgr HRESULT TF_GetThreadMgr( ITfThreadMgr **pptim );
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctf.h", MSDNShortId = "NF:msctf.TF_GetThreadMgr")]
public static extern HRESULT TF_GetThreadMgr(out ITfThreadMgr pptim);
///
/// The TF_InvalidAssemblyListCacheIfExist function invalidates the text input processor's description cache. It is not
/// necessary to call this function if the input processor setup program requires you to restart or log on. The cache is valid until
/// the user logs off.
///
///
/// This function can return one of these values.
///
///
/// Return code
/// Description
///
/// -
/// S_OK
/// The function was successful.
///
/// -
/// E_FAIL
/// An unspecified error occurred.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/tsf/tf-invalidassemblylistcacheifexist HRESULT TF_InvalidAssemblyListCacheIfExist(void);
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("")]
public static extern HRESULT TF_InvalidAssemblyListCacheIfExist();
/// The UninitLocalMsCtfMonitor function uninitializes TextServicesFramework on the current desktop.
///
///
///
/// Value
/// Meaning
///
/// -
/// S_OK
/// The function was successful.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/msctfmonitorapi/nf-msctfmonitorapi-uninitlocalmsctfmonitor HRESULT UninitLocalMsCtfMonitor();
[DllImport(Lib_Msctf, SetLastError = false, ExactSpelling = true)]
[PInvokeData("msctfmonitorapi.h", MSDNShortId = "NF:msctfmonitorapi.UninitLocalMsCtfMonitor")]
public static extern HRESULT UninitLocalMsCtfMonitor();
///
[PInvokeData("")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct LAYOUTORTIP
{
///
public LOT dwFlags;
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Kernel32.MAX_PATH)]
public string szId; // Id of the keyboard item in the string format.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Kernel32.MAX_PATH)]
public string szName; // The description of the keyboard item.
}
///
[PInvokeData("")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct LAYOUTORTIPPROFILE
{
///
public LOTP dwProfileType; // InputProcessor or HKL
///
public LANGID langid; // language id
///
public Guid clsid; // in Guid of tip
///
public Guid guidProfile; // profile description
///
public Guid catid; // category of tip
///
public uint dwSubstituteLayout; // substitute hkl
///
public uint dwFlags; // Flags
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Kernel32.MAX_PATH)]
public string szId; // KLID or TIP profile for string
}
}
}