vo_to_net:pcall
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
vo_to_net:pcall [2018/07/09 04:39] – wolfgangriedmann | vo_to_net:pcall [2018/07/29 05:22] (current) – wolfgangriedmann | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PCall vs PCallNative ====== | ====== PCall vs PCallNative ====== | ||
- | In the first Vulcan versions, | + | '' |
- | < | + | |
- | There was only a function '' | + | The X# compiler needs a typed function pointer for '' |
- | < | + | < |
- | Only later also support for '' | + | RETURN 0 |
- | To call a function dynamically with a locally defined function pointer, the '' | + | .... |
+ | local hFunc as __GetRealOsVersion ptr | ||
+ | dword( _cast , PCALL( hFunc ,@struOS) | ||
+ | The alternative (to not define such a function) is to use '' | ||
+ | < | ||
+ | PCALLNative<dword>( hFunc ,@struOS | ||
+ | |||
+ | The .NET way would be the definition of a delegate (i.e. a typed function pointer). Please see [[: | ||
+ | A sample for the delegate version | ||
+ | <code visualfoxpro> | ||
+ | local oFunc as RtlGetVersionDelegate | ||
+ | |||
+ | oFunc := ( RtlGetVersionDelegate | ||
+ | oFunc: | ||
+ | |||
+ | To simplify the code, a static method could help: | ||
+ | <code visualfoxpro> | ||
+ | |||
+ | static method CreateDelegate< | ||
+ | local oFunc as T | ||
+ | local oDelegate as object | ||
+ | |||
+ | oDelegate := Marshal.GetDelegateForFunctionPointer( hFunc, TypeOf( T ) ) | ||
+ | |||
+ | oFunc := ( T ) oDelegate | ||
+ | |||
+ | return oFunc | ||
+ | |||
+ | end class</ | ||
+ | and to be used: | ||
+ | <code visualfoxpro> | ||
+ | (Code courtesy of Chris Pyrgas) | ||
+ | |||
+ | The X# development team recommends | ||
The following was stated by a member of the development team: | The following was stated by a member of the development team: | ||
Line 13: | Line 46: | ||
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.'' | 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: | + | Please see more details in the X# Forum discussion: |
[[https:// | [[https:// | ||
+ | |||
+ | Please note: | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | The best option to call a function from a dynamically loaded DLL is to define a delegate, assign the function pointer to it and call then the delegate. | ||
+ | |||
+ | In VO, dynamically loading DLLs and executing function from it was interesting to make the application loading times shorter, but in .NET thanks to its lazy loading this is not more necessary. | ||
+ | |||
+ | Executing functions dynamically is only needed when you are not sure that the functionality is installed, or if you are using different versions dependent on some other parameters like OS version or 3rd party DLL version. |
vo_to_net/pcall.1531111155.txt.gz · Last modified: 2018/07/09 04:39 by wolfgangriedmann