User Tools

Site Tools


calling_20dlls_20that_20return_20floats

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

calling_20dlls_20that_20return_20floats [2018/03/31 13:19]
127.0.0.1 external edit
calling_20dlls_20that_20return_20floats [2018/04/14 17:06] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Calling DLLs that return floats===== =====Calling DLLs that return floats=====
  
-//by Richard Russell, May 2007, amended April 2013//\\ \\  BBC BASIC for Windows implements the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin7.html#​sys|SYS]] statement for calling routines in external DLLs (Dynamic Link Libraries). This statement has an optional **TO** clause which specifies a variable that should receive an integer value (if any) returned from the DLL:\\ \\ +//by Richard Russell, May 2007, amended April 2013//\\ \\  BBC BASIC for Windows implements the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin7.html#​sys|SYS]] statement for calling routines in external DLLs (Dynamic Link Libraries). This statement has an optional **TO** clause which specifies a variable that should receive an integer value (if any) returned from the DLL: 
 + 
 +<code bb4w>
         SYS DLLfunction%,​ parameters TO result%         SYS DLLfunction%,​ parameters TO result%
-Here the variable **result%** receives the value returned from the DLL, which may be a result code (e.g. indicating success/​failure),​ an integer numeric value or a pointer (e.g. to data in memory).\\ \\  However very occasionally you may want to call a DLL function that returns a **floating point** value rather than an integer. You cannot do that directly using the **SYS** statement, but you can using the **FN_sysfloat** function listed later in this article. The syntax for that is as follows:\\ \\ +</​code>​ 
 + 
 +Here the variable **result%** receives the value returned from the DLL, which may be a result code (e.g. indicating success/​failure),​ an integer numeric value or a pointer (e.g. to data in memory).\\ \\  However very occasionally you may want to call a DLL function that returns a **floating point** value rather than an integer. You cannot do that directly using the **SYS** statement, but you can using the **FN_sysfloat** function listed later in this article. The syntax for that is as follows: 
 + 
 +<code bb4w>
         SYS FN_sysfloat(DLLfunction%,​ result#), parameters         SYS FN_sysfloat(DLLfunction%,​ result#), parameters
-Here the floating point value returned from the DLL is copied into the variable **result#​**. Note that this variable //must// be able to accept a 64-bit //double// value, otherwise your program will most likely fail catastrophically! Hence either the variable name must have a **#** suffix or your program must run in the ***FLOAT64** mode. Since it is acceptable to specify an explicit # suffix in both *FLOAT40 and *FLOAT64 modes this is the safest option.\\ \\  Note that sometimes DLL functions return floating-point values in a different way: by requiring you to pass a pointer to a memory location at which the value will be stored. In that case the ordinary **SYS** statement can be used and there is no need to adopt the technique described in this article.\\ \\  The **FN_sysfloat** function is listed below. It relies for its operation on undocumented internal behaviour of the BBC BASIC for Windows interpreter,​ so cannot be guaranteed to work with all future versions:\\ \\ +</​code>​ 
 + 
 +Here the floating point value returned from the DLL is copied into the variable **result#​**. Note that this variable //must// be able to accept a 64-bit //double// value, otherwise your program will most likely fail catastrophically! Hence either the variable name must have a **#** suffix or your program must run in the ***FLOAT64** mode. Since it is acceptable to specify an explicit # suffix in both *FLOAT40 and *FLOAT64 modes this is the safest option.\\ \\  Note that sometimes DLL functions return floating-point values in a different way: by requiring you to pass a pointer to a memory location at which the value will be stored. In that case the ordinary **SYS** statement can be used and there is no need to adopt the technique described in this article.\\ \\  The **FN_sysfloat** function is listed below. It relies for its operation on undocumented internal behaviour of the BBC BASIC for Windows interpreter,​ so cannot be guaranteed to work with all future versions: 
 + 
 +<code bb4w>
         DEF FN_sysfloat(D%,​ RETURN R%)         DEF FN_sysfloat(D%,​ RETURN R%)
         DIM R% LOCAL -1         DIM R% LOCAL -1
Line 22: Line 32:
         ]         ]
         =C%         =C%
 +</​code>​
calling_20dlls_20that_20return_20floats.txt · Last modified: 2018/04/14 17:06 by richardrussell