>> Rodney Roberts IS & Education Professional Homepage >> Programming Tutorials And Downloads
![]() ![]()
Science makes it known,
|
D program calling XBLite Library
This page discusses developing D main programs (also applies to D .dll)
calling functions in a XBLite dynamic link Library (.dll). In this
example, the D main program initializes the XBLite .dll, then calls four
functions to calculate an ellipse perimeter.
Sample D Code Below is a listing of the D command console main program (dellips.d - developed on an AMD Athlon II running WinXP Pro SP3 using import std.stdio; import core.runtime; // implib /system ellps125.lib ellps125.dll // /system Prepend '_' to exported internal names (NT system DLL) extern (C) { int xbEntry2c () nothrow; float XBgauskumc (float a, float b) nothrow; float XBgkcc (float a, float b) nothrow; float XBeulerc (float a, float b) nothrow; float XBmaclaurinc (float a, float b) nothrow; } int main(string[] args) { float a, b, p; int i; printf(" \n"); try { Runtime.initialize; } catch (Throwable e) { printf(" dellips - threw initialize error"); return (0); } // ----- ----- ----- ----- ----- i = xbEntry2c (); printf(" xbEntry2c result %d \n", i); a = 20.0; b = 10.0; p = XBgauskumc (a, b); printf(" %f, %f, %f \n", a, b, p); p = XBgkcc (a, b); printf(" %f, %f, %f \n", a, b, p); printf(" \n"); // ----- ----- ----- ----- ----- try { Runtime.terminate; } catch (Throwable e) { return (0); } return (0); } XBLite Library ELLPS125.X is a port from Microsoft EXCEL Visual Basic to XBLite of several ellipse perimeter functions3. Used the same approach as in the USPS Address Matching System Application Programming Interface (AMS API) (see Using Fujitsu COBOL 3.0 to call the USPS AMS API) - two declarations for each function, each with a different LinkageType.1 The first is the XBLite "default protocol" from DECLARE FUNCTION, the second is DECLARE CFUNCTION.4 The D program calls the CFUNCTION, the CFUNCTION calls the FUNCTION. The FUNCTION subprograms have been successfully called by a XBLite Windows program. The CFUNCTION has the same name as the FUNCTION with a 'c' appended. Developed on a Dell Optiplex GX150 running WinXP Pro SP2.
Compiling and Linking
![]() 1. "If the library was created from a C program, then it will probably be compatible with XBLite." - XBLite documentation In the D statement extern (C) {...}, C is the LinkageType. Other available D LinkageTypes are: Pascal, C++, D, Windows, and System. Judging by the compiler behavior, using these other LinkageTypes (with the exception of Pascal - see Pascal calling D and FORTRAN footnotes) seems to cause some sort of name mangling. Pascal LinkageType requires passing the arguments in reverse order. 2. Without any changes whatsoever to the called subprogram, in an all XBLite application arguments may be passed by value, by reference, or by address (pointer) by the calling program. Another example, SSHORT (short in D) variables are stored as SLONG (int in D) internally. XBLite's "default protocol" does not seem supportive of being called by non-XBLite programs passing arguments by reference/address. 3. Chandrupatla, Tirupathi R., and Thomas J. Osler (2010). The Perimeter Of An Ellipse Mathematical Scientist. Review / comparison of four ellipse perimeter calculation methods. Elliptical area / perimeter calculations can be complex, involving geometric angles, parametric angles, integrations. 4. "CDECL protocol" - declares/defines C functions or C callable functions. |
|||||||
Any and all © copyrights, ™ trademarks, or other intellectual
property (IP) mentioned here are the property of their respective owners. No
infringement is intended.
Feel free to use any of the above in your project (without violating any intellectual property rights); please give credit (same idea as Copyleft). Page best viewed with Mozilla FireFox 2.0.0.6 (or higher) - Internet Explorer may not display correctly. Avoid Smart Applications Speed Browser. Website is supported on DESKTOP platforms only (will display on a NextBook Ares 8 Android tablet in a Chrome browser). |
Web hosting provided by: | ||||
![]() |
, | ![]() |
, & |
![]() |
>> Rodney Roberts IS & Education Professional Homepage >> Programming Tutorials And Downloads