Windows 7 SP1(x64)
Embarcadero® Delphi 10.2 Version 25.0.26309.314
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class $C0000005 with message 'access violation at 0xfeeefeee: read of address 0xfeeefeee'.
---------------------------
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Winapi.MsCTF;
type
TForm1 = class(TForm)
btnSTF: TButton;
Memo1: TMemo;
procedure btnSTFClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnSTFClick(Sender: TObject);
var
profiles: PPTfInputProcessorProfiles;
Iprofiles: ITfInputProcessorProfiles;
plangid: Word;
enumerator: IEnumTfLanguageProfiles;
langProfile: TF_LANGUAGEPROFILE;
FetchedItems: Cardinal;
pbstrProfile: WideString;
pfEnable: Integer;
begin
if not IsMSCTFAvailable() then
Exit;
if TF_CreateInputProcessorProfiles(profiles) = (S_OK) then
begin
Iprofiles := ITfInputProcessorProfiles(profiles^);
Iprofiles.GetCurrentLanguage(plangid);
Memo1.Lines.Add(IntToStr(plangid));
if plangid > -1 then
begin
Iprofiles.EnumLanguageProfiles(plangid, enumerator);
if Assigned(enumerator) then
begin
enumerator.Next(1, langProfile, FetchedItems);
while FetchedItems > 0 do
begin
// Memo1.Lines.Add(langProfile.clsid.ToString());
// Memo1.Lines.Add(langProfile.langid.ToString());
// Memo1.Lines.Add(langProfile.fActive.ToString()); // -1时为当前激活输入法
pbstrProfile := '';
if Iprofiles.GetLanguageProfileDescription(langProfile.clsid, langProfile.langid, langProfile.guidProfile, pbstrProfile) = S_OK then
begin
//Memo1.Lines.Add(pbstrProfile);
if Iprofiles.IsEnabledLanguageProfile(langProfile.clsid, langProfile.langid, langProfile.guidProfile, pfEnable) = S_OK then
begin
if pfEnable = 1 then
begin
//显示TSF输入法名称
Memo1.Lines.Add(pbstrProfile);
//激活指定输入法(clsid、 guidProfile为空时,取消激活)
if pbstrProfile = '微软ABC' then
Iprofiles.ActivateLanguageProfile(langProfile.clsid, langProfile.langid, langProfile.guidProfile);
end;
end;
end;
enumerator.Next(1, langProfile, FetchedItems);
end;
end;
end;
end;
end;
end.
转载:https://blog.csdn.net/harvardfeng/article/details/77962291