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 06:46] – wolfgangriedmann | vo_to_net:pcall [2018/07/29 05:22] (current) – wolfgangriedmann | ||
---|---|---|---|
Line 3: | Line 3: | ||
'' | '' | ||
- | 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 '' | ||
- | local hFunc as ptr< | + | <code visualfoxpro> |
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: | ||
+ | <code visualfoxpro> | ||
+ | local oFunc as RtlGetVersionDelegate | ||
- | The X# development team reccommends | + | oFunc := ( RtlGetVersionDelegate ) Marshal.GetDelegateForFunctionPointer( hFunc, TypeOf( 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 22: | 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.1531291589.txt.gz · Last modified: 2018/07/11 06:46 by wolfgangriedmann