130 likes | 378 Views
Using EXTERN. Dave Doulton. Contents. What are EXTERN functions? How do you use them? How do you create them? Examples of usage. What are EXTERN Functions?. EXTERN and EXTERNS are two functions held in the extern.dll (Dynamically Linked Library).
E N D
Using EXTERN Dave Doulton Information Systems Services
Contents • What are EXTERN functions? • How do you use them? • How do you create them? • Examples of usage. Information Systems Services
What are EXTERN Functions? • EXTERN and EXTERNS are two functions held in the extern.dll (Dynamically Linked Library). • These functions can do anything you wish provided you can create the dll. • Your dll is placed in the SIR directory in place of the supplied version. • Note they can both take string or numeric parameters which can do different things but only return a numeric from EXTERN and a string from EXTERNS Information Systems Services
How do you use them? • EXTERN • num = EXTERN ( X ) • Invokes a user-supplied external function from the EXTERN dll. • The function can take a numeric or string parameter and calls a different user function for each case. • The extern.dll library supplied by SIR contains dummy functions which return zero. • EXTERNS • str = EXTERNS ( X ) • Invokes a user-supplied external function from the EXTERN dll. • The function can take a numeric or string parameter and calls a different user function for each case. • The extern.dll library supplied by SIR contains dummy functions which return blank (a zero length string). Information Systems Services
How do you create them? • To create the functions you can used the supplied template which can be found in the api/examples subdirectory of the directory where SIR is installed. Information Systems Services
How do you create them? • // • // Skeleton of user defined EXTERN function. • // • // Use this to build your own extern.dll to use the PQL EXTERN and EXTERNS functions. • // See the examples in the API directory. • // • #ifndef __StdCall • #ifdef _WIN32 • #define __StdCall __stdcall • #else • #define __StdCall • #endif • #endif • // • // The sirdbms executable links to these functions as defined: • // • const char * __StdCall SIRExtern1 (char * buffer); • double __StdCall SIRExtern2 (char * buffer); • const char * __StdCall SIRExtern3 (double num); • double __StdCall SIRExtern4 (double num); Information Systems Services
How do you create them? • // • // PQL Function str=EXTERNS(string) • // • const char * __StdCall SIRExtern1 (char * buffer) { • return ""; • } • // • // PQL Function num=EXTERN(string) • // • double __StdCall SIRExtern2 (char * buffer) { • return 0; • } • // • // PQL Function str=EXTERNS(num) • // • const char * __StdCall SIRExtern3 (double num) { • return ""; • } • // • // PQL Function num=EXTERN(num) • // • double __StdCall SIRExtern4 (double num) { • return 0; • } Information Systems Services
Examples of usage • David Baxter has made a dll that reads web pages. • Note not all web pages can be read. It is a matter of trial and error to check if the pages you want are readable. • The web addresses are entered without the http:// in the version I am using and that will be available on the SUG website. Information Systems Services
Examples of usage • I have 5 example programs • Writing the contents of a web page to a file. • Reading Share prices from the msn money website. • Reading Weather information from the BBC weather website. • Reading Train Live Running from the National rail website. • Reading Formula 1 results from F1 web pages Information Systems Services
Examples of usage • The descriptions of the extern functionality in this dll are as follows: • num=EXTERN(string) • It takes a url filename and returns a socket id. It’s quick and dirty and just goes to port 80 • str=EXTERNS(num) • Num is the socket id from before and it returns a single character at a time from the http server. • num=EXTERN(num) • Num is the socket id from before and cleans up. Information Systems Services
Examples of usage • The example programs use a subprocedure to read from the web server up to the next >. • This usually results in fairly small chunks of text to analyse. • The lines are searched for predetermined text that allows the extraction of the required data. Information Systems Services
Examples of usage • See the example programs. Information Systems Services
Any Questions? Information Systems Services