我正在遍历一堆.lnk
文件并获取有关它们的信息。
对于我这样做的每个文件,这是 js-ctypes 但这是一个 winapi 问题。我删除了错误检查并简化了代码:
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')();
但是ppropvar.pwszVal
出来的是我IPersitFile::Load
编辑的第一个文件的 SystemAppUserModelID,这是预期的吗?我必须CoUninitialize
和CoInitialize
每个循环或其他东西来解决这个问题吗?
谢谢