尝试使用下面提到的方法来获取有关锁定文件的更多详细信息。
function GetFileInUseInfo(const FileName : WideString) : IFileIsInUse;
var
ROT : IRunningObjectTable;
mFile, enumIndex, Prefix : IMoniker;
enumMoniker : IEnumMoniker;
MonikerType : LongInt;
unkInt : IInterface;
begin
result := nil;
OleCheck(GetRunningObjectTable(0, ROT));
OleCheck(CreateFileMoniker(PWideChar(FileName), mFile));
OleCheck(ROT.EnumRunning(enumMoniker));
while (enumMoniker.Next(1, enumIndex, nil) = S_OK) do
begin
OleCheck(enumIndex.IsSystemMoniker(MonikerType));
if MonikerType = MKSYS_FILEMONIKER then
begin
if Succeeded(mFile.CommonPrefixWith(enumIndex, Prefix)) and
(mFile.IsEqual(Prefix) = S_OK) then
begin
if Succeeded(ROT.GetObject(enumIndex, unkInt)) then
begin
if Succeeded(unkInt.QueryInterface(IID_IFileIsInUse, result)) then
begin
result := unkInt as IFileIsInUse;
exit;
end;
end;
end;
end;
end;
end;
但是调用
unkInt.QueryInterface(IID_IFileIsInUse, result)
总是返回E_NOINTERFACE
。
平台:Windows 7 32 位操作系统,打开 word 文件和 .msg 文件。
检查从资源管理器打开文件并尝试删除。它显示了有关打开文件的应用程序的正确详细信息。在我的应用程序中,我尝试显示有关打开文件的应用程序的信息。但是当尝试将指针转换为IFileIsInUse
接口时,QueryInterface
调用失败并返回代码E_NOINTERFACE
,这意味着 ROT 中的对象没有实现IFileIsInUse
。AFASIK,MS Office 文件实现IFileIsInUse
知道这里有什么问题吗?