IQuerySolution.Resolve导致访问冲突

时间:2019-01-25 20:50:58

标签: delphi winapi windows-search

我正在尝试呼叫 IQuerySolution.Resolve ,但是在StructuredQuery.dll的内部存在访问冲突。

示例代码

program Project3;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  ComObj,
  ActiveX,
  Windows,
  Winapi.StructuredQuery,
  Winapi.StructuredQueryCondition;

function GetUserDefaultUILanguage: LANGID; stdcall; external 'kernel32.dll' name 'GetUserDefaultUILanguage';

procedure Main(InputString: UnicodeString);
var
    cond: ICondition;
    manager: IQueryParserManager;
    parser: IQueryParser;
    solution: IQuerySolution;
    st: SYSTEMTIME;
    resolved: ICondition;
    hr: HRESULT;
type
    PIEnumUnknown = ^IEnumUnknown;
    PIEntity = ^IEntity;
begin
    manager := CreateComObject(CLSID_IQueryParserManager) as IQueryParserManager;

    OleCheck(manager.CreateLoadedParser(PWideChar('SystemIndex'), GetUserDefaultUILanguage, IQueryParser, {var}Pointer(parser)));
    parser._AddRef; //since it was passed as a naked pointer

    OleCheck(parser.Parse(PWideChar(InputString), PIEnumUnknown(nil)^, {out}solution));

    OleCheck(solution.GetQuery({out}cond, PIEntity(nil)^));

    {
        IQueryCondition::Resolve and IConditionFactory2::ResolveCondition turn any date/time references
        (relative, such as "today", and absolute, such as "5/7/2009") into absolute date/time references
        (in the UTC time zone), and also simplifies the result in various ways.
    }

    GetLocalTime({var}st);
    hr := solution.Resolve({var}cond, 0, {var}st, {out}resolved); //<--access violation
    OleCheck(hr);
end;

begin
  try
        CoInitialize(nil);
        Main('Chester Copperpot');
        WriteLn('Press enter to close');
        Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

故障在线发生:

solution.Resolve(condition, 0, systemTime, {out}resolved);

enter image description here

直接从Microsoft结构化查询示例(available on GitHub)中翻录并转码代码

我在做什么错了?

0 个答案:

没有答案