RAD Studio (Common)
ContentsIndex
PreviousUpNext
W1053: Local PInvoke code has not been made because external routine '%s' in package '%s' is defined using package local types in its custom attributes

This warning may arise when an external package uses PInvoke to access Win32 library code, and that package exposes the PInvoke definition through a public export. In these cases the compiler will attempt to link directly to the Win32 library by copying the PInvoke definition to the local assembly, rather than linking to the public export in the external package. This is more secure and can also improve runtime performance. 

This warning message is issued if the compiler is unable to emit the PInvoke definition locally, because the external assembly uses locally-defined types for a custom attribute. To avoid this warning, you must change the named package so that it does not use locally-defined types for a custom attribute in an exported function or procedure. 

For example, in the following code, the unit ExternalPackagedUnit exposes the external function Beep in kernel32 through the TFoo.Beep function, with the MyAttribute custom attribute:

unit ExternalPackagedUnit;

interface

function Beep(dwFreq, dwDuration: MyLongWord): Boolean; static; stdcall;

implementation

type
  MyAttribute = class(System.Attribute)
  .
  .
  .
  end;

[MyAttribute]
function Beep(dwFreq, dwDuration: LongWord): Boolean; stdcall; external 'kernel32' name 'Beep';

end.

If one attempts to compile a program which uses ExternalPackagedUnit, then because the MyAttribute type is locally-defined in ExternalPackagedUnit the compiler will be unable to link directly to the Beep function in kernel32, and this warning will be issued. In the example, this problem can be solved by making the MyAttribute type public (by moving its declaration from the implementation section to the interface section), or by removing the custom attribute from the Beep function.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!