User Tools

Site Tools


vo_to_net:pcall

This is an old revision of the document!


PCall vs PCallNative

PCall() and PCallNative() are pseudo-functions or intrinsic functions - they do not need any runtime because they are replaced by the compiler.

The X# compiler needs a typed function pointer for PCall() to work:

STATIC FUNCTION __GetRealOsVersion( struOS AS _winOSVERSIONINFOEX) AS DWORD PASCAL  // typed function pointer
  RETURN 0
....
local hFunc as __GetRealOsVersion ptr
dword( _cast , PCALL( hFunc ,@struOS) )

The alternative (to not define such a function) is to use PCallNative(): local hFunc as ptr

PCALLNative<dword>( hFunc ,@struOS )

The .NET way would be the definition of a delegate (i.e. a typed function pointer). Please see Delegates.

The X# development team reccommends the use of PCall() over PCallNative() because the X# compiler will build a delegate from the typed function pointer and use it.

The following was stated by a member of the development team:

A delegate is created by the compiler and the parameters for the delegate have to be determined by the compiler . In the case of PCallNative it looks at the actual arguments to “guess” the types. The return type is then the type as specified in the code. In the case of PCall it copies both the parameter types and return value of the function in the declaration to the delegate. The compiler then emits the code to use the native function pointer and call this with the managed delegate. For this reason I would recommend using PCall because the function name used in the declaration gives you full control of the parameter types in the delegate.

Please see major details in the X# Forum discussion: www.xsharp.info/forum/public-product/752-voxporter-icon-naming-problem

vo_to_net/pcall.1531291589.txt.gz · Last modified: 2018/07/11 06:46 by wolfgangriedmann