Noitidart
Noitidart

Reputation: 37238

Using IPersistFile::Load multiple times with IPropertyStore

I am iterating through a bunch of .lnk files and getting information on them.

For each file I do this, this is js-ctypes but is a winapi question. I removed the error checking and simplified the code:

var hr_CoInitializeEx = ostypes.API('CoInitializeEx')(null, ostypes.CONST.COINIT_APARTMENTTHREADED);

var shellLinkPtr = ostypes.TYPE.IShellLinkW.ptr();
var hr_CoCreateInstance = ostypes.API('CoCreateInstance')(ostypes.CONST.CLSID_ShellLink.address(), null, ostypes.CONST.CLSCTX_INPROC_SERVER, ostypes.CONST.IID_IShellLink.address(), shellLinkPtr.address());
shellLink = shellLinkPtr.contents.lpVtbl.contents;

var persistFilePtr = ostypes.TYPE.IPersistFile.ptr();
var hr_shellLinkQI = shellLink.QueryInterface(ostypes.CONST.IID_IPersistFile.address(), persistFilePtr.address());
persistFile = persistFilePtr.contents.lpVtbl.contents;

var propertyStorePtr = ostypes.TYPE.IPropertyStore.ptr();
var hr_shellLinkQI2 = shellLink.QueryInterface(ostypes.CONST.IID_IPropertyStore.address(), propertyStorePtr.address());
propertyStore = propertyStorePtr.contents.lpVtbl.contents;

for (var i = 0; i < arrOSPath.length; i++) {
    var hr_Load = persistFile.Load(persistFilePtr, arrOSPath[i], 0);

    var ppropvar = ostypes.TYPE.PROPVARIANT();
    var hr_GetValue = propertyStore.GetValue(ostypes.CONST.PKEY_AppUserModel_ID.address(), ppropvar.address());
    console.log(ppropvar.pwszVal); ////// <<<<< this is fishy

    var rez_PropVariantClear = ostypes.API('PropVariantClear')(ppropvar.address());
}

// cleanup
persistFile.Release(persistFilePtr);
propertyStore.Release(propertyStorePtr);
shellLink.Release(shellLinkPtr);
ostypes.API('CoUninitialize')();

However ppropvar.pwszVal is coming out to be the SystemAppUserModelID of the first file I IPersitFile::Loaded, is this expected? Do I have to CoUninitialize and CoInitialize each loop or something to fix this?

Thanks

Upvotes: 1

Views: 236

Answers (0)

Related Questions