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/11 08:33] – wolfgangriedmann | vo_to_net:pcall [2018/07/29 05:22] (current) – wolfgangriedmann | ||
---|---|---|---|
Line 4: | Line 4: | ||
The X# compiler needs a typed function pointer for '' | The X# compiler needs a typed function pointer for '' | ||
- | < | + | < |
RETURN 0 | RETURN 0 | ||
.... | .... | ||
Line 10: | Line 10: | ||
dword( _cast , PCALL( hFunc ,@struOS) )</ | dword( _cast , PCALL( hFunc ,@struOS) )</ | ||
The alternative (to not define such a function) is to use '' | The alternative (to not define such a function) is to use '' | ||
- | < | + | < |
PCALLNative< | PCALLNative< | ||
The .NET way would be the definition of a delegate (i.e. a typed function pointer). Please see [[: | The .NET way would be the definition of a delegate (i.e. a typed function pointer). Please see [[: | ||
A sample for the delegate version is the following: | A sample for the delegate version is the following: | ||
- | < | + | < |
local oFunc as RtlGetVersionDelegate | local oFunc as RtlGetVersionDelegate | ||
oFunc := ( RtlGetVersionDelegate ) Marshal.GetDelegateForFunctionPointer( hFunc, TypeOf( RtlGetVersionDelegate ) ) | oFunc := ( RtlGetVersionDelegate ) Marshal.GetDelegateForFunctionPointer( hFunc, TypeOf( RtlGetVersionDelegate ) ) | ||
oFunc: | 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 use of '' | The X# development team recommends the use of '' | ||
Line 28: | 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:// | ||
Line 41: | Line 59: | ||
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. | 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 | + | Executing functions dynamically is only needed when you are not sure that the functionality is installed, or if you are using different versions |
vo_to_net/pcall.1531298013.txt.gz · Last modified: 2018/07/11 08:33 by wolfgangriedmann