我正在使用IGameExplorer COM对象在Inno Setup中使用Windows Games Explorer注册和注销游戏。虽然添加游戏工作正常,但是在“GEUnRegister”程序中从游戏资源管理器中删除游戏时,卸载程序崩溃了
OleCheck(myGEX.RemoveGame(StringToGuid(sGUID)));
这与IGameExplorer界面中的某些错误有关,或者我忽略了什么?任何帮助表示赞赏! :)
const
CLSID_GameExplorer = '{9a5ea990-3034-4d6f-9128-01f3c61022bc}';
GIS_CURRENT_USER = 2;
GIS_ALL_USERS = 3;
type
IGameExplorer = interface(IUnknown)
'{E7B2FB72-D728-49B3-A5F2-18EBF5F1349E}'
function AddGame(sGDFBinaryPath: String; sInstallDirectory: String; installScope: Word; var pguidInstanceID: TGUID): HResult;
function RemoveGame(instanceID: TGUID): HResult;
function UpdateGame(instanceID: TGUID): HResult;
function VerifyAccess(sGDFBinaryPath: String; var pHasAccess: Boolean): HResult;
end;
procedure GERegister;
var
myGEX: IGameExplorer;
myGUID: TGUID;
o: IUnknown;
bAccess: Boolean;
sGUID: String;
begin
o := CreateComObject(StringToGuid(CLSID_GameExplorer));
myGEX := IGameExplorer(o);
OleCheck(myGEX.VerifyAccess(ExpandConstant('{app}\mygame.exe'), bAccess));
if bAccess then
begin
myGUID := StringToGuid('{00000000-0000-0000-0000-000000000000}');
OleCheck(myGEX.AddGame(ExpandConstant('{app}\mygame.exe'), ExpandConstant('{app}'), GIS_ALL_USERS, myGUID));
//write guid to registry
sGUID := Format('{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}', [myGUID.D1, myGUID.D2, myGUID.D3, myGUID.D4[0], myGUID.D4[1], myGUID.D4[2], myGUID.D4[3], myGUID.D4[4], myGUID.D4[5], myGUID.D4[6], myGUID.D4[7]]);
RegWriteStringValue(HKEY_CURRENT_USER, 'Software\My Publisher\My Game',
'ge_guid', sGUID);
end;
end;
procedure GEUnRegister;
var
myGEX: IGameExplorer;
o: IUnknown;
sGUID: String;
begin
o := CreateComObject(StringToGuid(CLSID_GameExplorer));
myGEX := IGameExplorer(o);
sGUID := '';
if RegKeyExists(HKEY_CURRENT_USER, 'Software\My Publisher\My Game') then
begin
RegQueryStringValue(HKEY_CURRENT_USER, 'Software\My Publisher\My Game',
'ge_guid', sGUID);
if sGUID <> '' then
begin
OleCheck(myGEX.RemoveGame(StringToGuid(sGUID))); // <--- crashes the uninstaller
end;
end;
end;