1

考虑以下代码:

uses
  {... }
  ComObj,
  ShlObj;

type
  TContextMenu = class(TComObject, IShellExtInit, IContextMenu)
  private
  {(*}
  const
    GUID: TGUID = '{99D8B139-0855-4C5D-95E7-BC8EC6254B3D}';
  {*)}
  private
    FCmdCount: LongWord;
    FDm: Tdm_ContextMenu;
  protected
    function IShellExtInit.Initialize = IShellExtInit_Initialize;
    function IShellExtInit_Initialize(_pidlFolder: PItemIDList; _lpdobj: IDataObject;
      _HKeyProgID: HKEY): HResult; stdcall;
    function QueryContextMenu(_Menu: HMENU; _indexMenu, _idCmdFirst, _idCmdLast,
      _UFlags: UINT): HResult; stdcall;
    function InvokeCommand(var _ici: TCMInvokeCommandInfo): HResult; stdcall;
    function GetCommandString(_idCmd, _uType: UINT; _pwReserved: PUINT;
      _PszName: LPSTR; _cchMax: UINT): HResult; stdcall;
  public
    procedure Initialize; override;
    destructor Destroy; override;
  end;

这在 Delphi 2007 和 XE 中编译得很好,但 Delphi XE2 给了我错误:“[DCC Error] u_ContextMenuHandler.pas(16): E2291 Missing implementation of interface method IContextMenu.GetCommandString”

这让我很困惑。我检查了接口声明,我的 GetCommandString 函数与接口的声明完全相同。有什么提示吗?

4

2 回答 2

2

的正确声明GetCommandString是:

function GetCommandString(idCmd: UINT_PTR; uFlags: UINT; pwReserved: PUINT;
  pszName: LPSTR; cchMax: UINT): HResult; stdcall;

确保在写信之前检查GCS_UNICODEin的存在。该测试确定您是否应该返回 Unicode 或 ANSI 字符串。文档中描述了这种细微差别。uFlagspszName

于 2012-04-29T16:10:35.453 回答
2

在 XE2中声明了“_idCmd” UINT_PTR(针对 64 位时为 8 个字节)。

于 2012-04-29T16:16:26.140 回答