问题
Consider the following code:
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;
This compiles fine in Delphi 2007 and XE but Delphi XE2 gives me the error: "[DCC Error] u_ContextMenuHandler.pas(16): E2291 Missing implementation of interface method IContextMenu.GetCommandString"
This has me baffled. I checked the interface declaration and my GetCommandString function has the exactly the same declaration as the interface's. Any hints?
回答1:
'_idCmd' is declared UINT_PTR
(which is 8 bytes when targeting 64-bit) in XE2.
回答2:
The correct declaration of GetCommandString
is:
function GetCommandString(idCmd: UINT_PTR; uFlags: UINT; pwReserved: PUINT;
pszName: LPSTR; cchMax: UINT): HResult; stdcall;
Make sure that you check for the presence of GCS_UNICODE
in uFlags
before writing to pszName
. That test determines whether or not you should return a Unicode or ANSI string. This nuance is described in the documentation.
来源:https://stackoverflow.com/questions/10373636/why-do-i-get-the-error-missing-implementation-of-interface-method-in-delphi-xe2