2010. július 20., kedd

GetDocumentation for Type Library


Problem/Question/Abstract:

Recently I developed Automation Server for reports in Word and was surprised with failure trying to get Help String for TypeLibrary

Answer:

Recently I developed Automation Server for reports in Word and was surprised with failure trying to get Help String for TypeLibrary by following code

var
  k, InfoCount: Integer;
  TypeLib: ITypeLib;
  TypeLibGUID: TGUID;
  ErrorStr: string;
  HRes: HResult;
  pbstrDocString, pbstrName: WideString;
begin
  Memo1.Lines.Clear;
  // InputGUIDString is given input string value
  TypeLibGUID := StringToGUID(InputGUIDString);
  // loads Type Library from registry
  HRes := LoadRegTypeLib(TypeLibGUID, 1, 0, 0, TypeLib);
  if Failed(HRes) then
    Exit;

  // believing in mind, that so it is in practice!
  InfoCount := TypeLib.GetTypeInfoCount;
  for k := 0 to kInfoCount - 1 do
  begin
    HRes := TypeLib.GetDocumentation(k, @pbstrName, @pbstrDocString, nil, nil);
    if Failed(HRes) then
      Continue;
    Memo1.Lines.Add(pbstrName + ': ' + pbstrDocString);
  end;

Here was no errors!
But the thing is that help string for Type Library resides beyond the range [0..kInfoCount-1] so TypeLib.GetTypeInfoCount reports about ITypeInfo count, excluding ITypeInfo for himself. Did you know about it?
To get Help String for self Type Library one must implement

TypeLib.GetDocumentation(-1, @pbstrName, @pbstrDocString, nil, nil);

Isn't it unexpectedly for Delphi programmers? I didn't found anything about it in Delphi help!

Nincsenek megjegyzések:

Megjegyzés küldése