Enumerate installed Packages in Windows 8+ with Delphi 10 -


delphi 10 comes windows rt headers translated pascal. based on this c++ code trying enumerate installed metro applications in windows 8+. problem is, don't know how iterator correctly, iiterable_1__ipackage. findpackages method of deployment_ipackagemanager called correctly, , can confirm scanning memory process (before , after method call). process memory contains strings microsoft.skypeapp etc. packages ready iterated. once set iiterator_1__ipackage first package, becomes invalid pointer value (on pc $3). wonder now, if has incorrect rt headers in delphi or me approaching iteration process wrong way (most likely). current code:

program packagesmanager;  {$apptype console}  {$r *.res}  uses   winapi.windows,   system.sysutils,   winapi.management,   winapi.applicationmodel,   winapi.winrt,   system.win.comobj;  var   lclassid: hstring;   pinspectable: iinspectable;   pact: iactivationfactory;   packagemanager: deployment_ipackagemanager;   pkgs: iiterable_1__ipackage;   piter: iiterator_1__ipackage;   hascurrent: boolean;   packageid: ipackageid;   package: ipackage; begin   // com/runtime object initialization   olecheck(roinitialize(ro_init_singlethreaded));    try     if succeeded(windowscreatestring(pwidechar(sdeployment_packagemanager),       length(sdeployment_packagemanager), lclassid))     begin       // activation factory       olecheck(rogetactivationfactory(lclassid, iactivationfactory,         pinspectable));        // activate or create instance activation factory       pact := pinspectable iactivationfactory;       pact.activateinstance(pinspectable);        // extract packagemanager via queryinterface       olecheck(pinspectable.queryinterface(deployment_ipackagemanager,         packagemanager));        // `iiterable` collection of packages       //       // after below call, process memory contains strings package names       // i.e. microsoft.skypeapp, means findpackages called       // confirmed scanning process memory known strings,       // before , after findpackages call       pkgs := packagemanager.findpackages;        // iterator iiterable       piter := pkgs.first; // piter $00000003...        hascurrent := piter.hascurrent; // access violation       while hascurrent       begin         package := piter.current;         packageid := package.id;         hascurrent := piter.movenext;       end;     end;       rouninitialize;   end; end. 

i'm not looking read registry or set ntfs access in %programfiles\windowsapps solution, because base project functionality expanded. being able list packages in elegant & microsoft designed way great start.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -