SlideShare a Scribd company logo
1 of 12
Download to read offline
DLL Building Blocks 
Yes, we scan… 
http://en.wikipedia.org/wiki/Web_of_Things 
Max Kleiner 
Script: 362_maxon3D_EKON18.TXT
Agenda and Tutorial 
(DLL 32/64 bit) 
2 
http://www.softwareschule.ch/download/maxbox_starter28.pdf 
• Call a DLL 
• Call a DLL+ (Interface, Callback, Events) 
• Build a DLL 
• Recompile a DLL 
• Android NDK and Lazarus 
http://scholz2000.com/ 
136_sysinformation_dll_EKON1.txt 
A Short History of Time 
1991 Application Program 
1995 Application 
1998 Applet 
2010 App 
2015 A (Scholz2000, Android, Arduino, ARM)
DLL Primer •• 
Call: If you want your library to be called from programs compiled with 
other compilers, it is important to specify the correct calling convention. 
•• 
Create: A library can be created just as a program, only it uses the 
library keyword, and it has an exports section. 
•• 
Let's get back to the topic and create a DLL callback function: 
•• 
1. declare a function type 
• 2. the function itself 
• 3. define the DLL reference 
• 4. then implement the function in the client 
• 5. and call the DLL: 
3 
136_sysinformation_dll_EKON1.txt 039_pas_dllcall_EKON2.txt 
070_pas_functionplotter_digital2.txt
CCaallllbbaacckk hhaacckk ssttaacckk 
• 
4 
Callback example in client unit 136_Callback_dll_EKON6.txt 
----------------------------------------------- 
interface... 
1. TCallBackFunction = function(sig: integer):boolean; 
2. function callME(sig: integer):boolean; 
implement... 
3. procedure TestCallBack(myCBFunction: TCallBackFunction); register; 
external('watchcom.dll'); 
4. function callMe(sig: integer): boolean; 
begin 
{whatever you need to do, case of...} 
showmessage('I was called with'+ inttostr(sig)); 
end; 
5. procedure TForm1.Button1Click(sender: TObject); 
begin 
testCallBack(callMe); //subscribe function in DLL 
end;
Create a DLL 
5 
Callback in the DLL 
In the DLL you would also declare a function type and a 
procedure (or function) itself, so use it like this: 
type 
TCallBackFunction = function(sig: integer):boolean; 
procedure TestCallBack(clientFunc: TCallBackFunction); stdcall; 
var sigAlive: boolean; 
begin 
{timer stuff... 
set the signal...} 
if(clientFunc(55)) then sigalive := true; 
end; 
exports TestCallBack;
http://max.kleiner.com/dllplus.htm 
6 
Export an object-reference from a DLL is one approach to get real OO-access 
to a DLL. The DLL must create and return the object, so the client 
gets the methods without encapsulating. 
unit income1; 
interface 
type 
IIncome = class 
public 
function GetIncome(const aNetto: Currency): Currency; 
virtual; abstract; 
procedure SetRate(const aPercent, aYear: integer); 
virtual; abstract; 
function queryDLLInterface(var queryList: TStringList): 
TStringList; virtual; abstract; 
end; 
036_pas_includetest_EKON3.txt 
036_pas_dynlib_EKON4.txt 
036_pas_DLLTesting_EKON5.tx
Solution FPC ELF32 
shared object 
7 
32-bit EXE loads 32-bit DLL, 64-bit EXE loads 64-bit DLL. 
************* Simple Sequence Diagram************** 
Client DLL 
¦ TestCallBack(clientFunc) ¦ 
¦---------------------------------------------->¦ 
¦ clientFunc.callMe(sig ) ¦ 
¦<----------------------------------------------¦ 
¦ ¦ 
¦ true (or something to return) ¦ 
¦---------------------------------------------->¦ 
¦ ¦ 
http://wiki.freepascal.org/Android_Programming 
http://www.softwareschule.ch/examples/440_DLL_Tutor2.txt 
Tutor: http://www.softwareschule.ch/download/maxbox_starter18_3.pdf
Solution NDK 
The NDK is a toolset that allows you to implement parts of your app using 
native-code languages such as C, Pascal, Object Pascal and C++. For certain 
types of apps, this can be helpful so you can reuse existing code libraries 
written in these languages, but most apps do not need the Android NDK. 
Typical good candidates for the NDK are CPU-intensive workloads such as 
game engines, signal processing, physics simulation, and so on. When 
examining whether or not you should develop in native code, think about your 
requirements and see if the Android framework APIs provide the functionality 
that you need. 
You have to use the Android NDK to recompile the library. The ARM 
architecture is completely different from the x86 architecture. The system calls 
are different on Linux and Windows. 
8 
http://www.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html
NDK Need Things 
If you have the src files for the DLL, try recompiling as an ELF32 shared object, then link 
that instead into your Android code (- 
below is a Windows solution): 
set NDK_HOME=C:Androidandroid-ndk-r9c // customize this var for your own location 
set LD_LIBRARY_PATH=%NDK_HOME%platformsandroid-18arch-armusrlib cd 
REM -- TEMPORARILY COPY SOME LIBS COMPILER MAY NEED 
copy %NDK_HOME%platformsandroid-18arch-armusrlibcrtbegin*.o . 
copy %NDK_HOME%platformsandroid-18arch-armusrlibcrtend*.o . 
REM -- GENERATE YOUR OBJ FILE 
%NDK_HOME%toolchainsarm-linux-androideabi-4.8prebuiltwindows-x86_64binarm-linux-androideabi- 
gcc.exe -g -I%NDK_HOME%platforms 
android-18arch-armusrinclude -c -fPIC YourLib.c -o YourLib.o 
REM -- GENERATE SHARED OBJ FROM OBJ FILE 
%NDK_HOME%toolchainsarm-linux-androideabi-4.8prebuiltwindows-x86_64binarm-linux-androideabi- 
gcc.exe -g -L%NDK_HOME%platforms 
android-18arch-armusrlib -shared -o YourLib_so.so YourLib_so.o 
REM -- finally, remove the libraries previously copied to src directory 
del .crtbegin*.o 
del .crtend*.o 
9
Optional: Create <project>/jni/Application.mk. 
Build your native code by running the 'ndk-build' script from your project's directory. 
It is located in the top-level NDK directory: 
cd <project> 
<ndk>/ndk-build 
I discovered that to use the build-ndk script, I don't need a real project. 
I created a folder project, with nothing in it except another folder jni, and put all 
my sources in that folder. 
I then created the Android.mk file and ran the script as described in the ndk docs. 
10 
Here's the general outline of how you work with the NDK tools: 
Place your native sources under <project>/jni/... 
Create <project>/jni/Android.mk to describe your native sources to the NDK 
build system 
http://developer.android.com/sdk/ndk/index.html
Thanks! Links to Blocks 
the source is the code 
http://www.softwareschule.ch/maxbox.htm 
http://sourceforge.net/projects/maxbox 
http://en.wikipedia.org/wiki/Arduino 
http://www.softwareschule.ch/download/webofthings2013.pdf 
Book Patterns konkret 
http://www.amazon.de/Patterns-konkret-Max-Kleiner/dp/3935042469 
maXbox 
https://github.com/maxkleiner/maXbox3/releases 
11 
http://max.kleiner.com/dllplus.htm 
http://www.softwareschule.ch/download/dlldesign_ekon9.pdf 
http://developer.android.com/sdk/ndk/index.html 
http://www.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html
Questions? Code a World 
hack the earth 
12 
Yes, we hack… 
https://github.com/maxkleiner/maXbox3/releases

More Related Content

What's hot

GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
Miller Lee
 

What's hot (20)

C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
clWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPUclWrap: Nonsense free control of your GPU
clWrap: Nonsense free control of your GPU
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3HKG15-207: Advanced Toolchain Usage Part 3
HKG15-207: Advanced Toolchain Usage Part 3
 
С++ without new and delete
С++ without new and deleteС++ without new and delete
С++ without new and delete
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。
 
Tensor comprehensions
Tensor comprehensionsTensor comprehensions
Tensor comprehensions
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI веке
 
Exploring the Cryptol Toolset
Exploring the Cryptol ToolsetExploring the Cryptol Toolset
Exploring the Cryptol Toolset
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
 
Intel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correctionIntel IPP Samples for Windows - error correction
Intel IPP Samples for Windows - error correction
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
C++ amp on linux
C++ amp on linuxC++ amp on linux
C++ amp on linux
 
FTD JVM Internals
FTD JVM InternalsFTD JVM Internals
FTD JVM Internals
 
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
 

Similar to DLL Design with Building Blocks

Android on IA devices and Intel Tools
Android on IA devices and Intel ToolsAndroid on IA devices and Intel Tools
Android on IA devices and Intel Tools
Xavier Hallade
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
gopikahari7
 
Native Android for Windows Developers
Native Android for Windows DevelopersNative Android for Windows Developers
Native Android for Windows Developers
Yoss Cohen
 

Similar to DLL Design with Building Blocks (20)

Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
Android on IA devices and Intel Tools
Android on IA devices and Intel ToolsAndroid on IA devices and Intel Tools
Android on IA devices and Intel Tools
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
MattsonTutorialSC14.pptx
MattsonTutorialSC14.pptxMattsonTutorialSC14.pptx
MattsonTutorialSC14.pptx
 
MattsonTutorialSC14.pdf
MattsonTutorialSC14.pdfMattsonTutorialSC14.pdf
MattsonTutorialSC14.pdf
 
Native Android for Windows Developers
Native Android for Windows DevelopersNative Android for Windows Developers
Native Android for Windows Developers
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
01 dll basics
01 dll basics01 dll basics
01 dll basics
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programming
 
Introduction to Programming Lesson 01
Introduction to Programming Lesson 01Introduction to Programming Lesson 01
Introduction to Programming Lesson 01
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
 
CNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbgCNIT 126: 10: Kernel Debugging with WinDbg
CNIT 126: 10: Kernel Debugging with WinDbg
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Ch 6: The Wild World of Windows
Ch 6: The Wild World of WindowsCh 6: The Wild World of Windows
Ch 6: The Wild World of Windows
 

More from Max Kleiner

More from Max Kleiner (20)

EKON26_VCL4Python.pdf
EKON26_VCL4Python.pdfEKON26_VCL4Python.pdf
EKON26_VCL4Python.pdf
 
EKON26_Open_API_Develop2Cloud.pdf
EKON26_Open_API_Develop2Cloud.pdfEKON26_Open_API_Develop2Cloud.pdf
EKON26_Open_API_Develop2Cloud.pdf
 
maXbox_Starter91_SyntheticData_Implement
maXbox_Starter91_SyntheticData_ImplementmaXbox_Starter91_SyntheticData_Implement
maXbox_Starter91_SyntheticData_Implement
 
Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475Ekon 25 Python4Delphi_MX475
Ekon 25 Python4Delphi_MX475
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
maXbox Starter87
maXbox Starter87maXbox Starter87
maXbox Starter87
 
maXbox Starter78 PortablePixmap
maXbox Starter78 PortablePixmapmaXbox Starter78 PortablePixmap
maXbox Starter78 PortablePixmap
 
maXbox starter75 object detection
maXbox starter75 object detectionmaXbox starter75 object detection
maXbox starter75 object detection
 
BASTA 2020 VS Code Data Visualisation
BASTA 2020 VS Code Data VisualisationBASTA 2020 VS Code Data Visualisation
BASTA 2020 VS Code Data Visualisation
 
EKON 24 ML_community_edition
EKON 24 ML_community_editionEKON 24 ML_community_edition
EKON 24 ML_community_edition
 
maxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage coding
 
EKON 23 Code_review_checklist
EKON 23 Code_review_checklistEKON 23 Code_review_checklist
EKON 23 Code_review_checklist
 
EKON 12 Running OpenLDAP
EKON 12 Running OpenLDAP EKON 12 Running OpenLDAP
EKON 12 Running OpenLDAP
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures Coding
 
NoGUI maXbox Starter70
NoGUI maXbox Starter70NoGUI maXbox Starter70
NoGUI maXbox Starter70
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VII
 
maXbox starter68 machine learning VI
maXbox starter68 machine learning VImaXbox starter68 machine learning VI
maXbox starter68 machine learning VI
 
maXbox starter67 machine learning V
maXbox starter67 machine learning VmaXbox starter67 machine learning V
maXbox starter67 machine learning V
 
maXbox starter65 machinelearning3
maXbox starter65 machinelearning3maXbox starter65 machinelearning3
maXbox starter65 machinelearning3
 
EKON22_Overview_Machinelearning_Diagrams
EKON22_Overview_Machinelearning_DiagramsEKON22_Overview_Machinelearning_Diagrams
EKON22_Overview_Machinelearning_Diagrams
 

Recently uploaded

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 

Recently uploaded (20)

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 

DLL Design with Building Blocks

  • 1. DLL Building Blocks Yes, we scan… http://en.wikipedia.org/wiki/Web_of_Things Max Kleiner Script: 362_maxon3D_EKON18.TXT
  • 2. Agenda and Tutorial (DLL 32/64 bit) 2 http://www.softwareschule.ch/download/maxbox_starter28.pdf • Call a DLL • Call a DLL+ (Interface, Callback, Events) • Build a DLL • Recompile a DLL • Android NDK and Lazarus http://scholz2000.com/ 136_sysinformation_dll_EKON1.txt A Short History of Time 1991 Application Program 1995 Application 1998 Applet 2010 App 2015 A (Scholz2000, Android, Arduino, ARM)
  • 3. DLL Primer •• Call: If you want your library to be called from programs compiled with other compilers, it is important to specify the correct calling convention. •• Create: A library can be created just as a program, only it uses the library keyword, and it has an exports section. •• Let's get back to the topic and create a DLL callback function: •• 1. declare a function type • 2. the function itself • 3. define the DLL reference • 4. then implement the function in the client • 5. and call the DLL: 3 136_sysinformation_dll_EKON1.txt 039_pas_dllcall_EKON2.txt 070_pas_functionplotter_digital2.txt
  • 4. CCaallllbbaacckk hhaacckk ssttaacckk • 4 Callback example in client unit 136_Callback_dll_EKON6.txt ----------------------------------------------- interface... 1. TCallBackFunction = function(sig: integer):boolean; 2. function callME(sig: integer):boolean; implement... 3. procedure TestCallBack(myCBFunction: TCallBackFunction); register; external('watchcom.dll'); 4. function callMe(sig: integer): boolean; begin {whatever you need to do, case of...} showmessage('I was called with'+ inttostr(sig)); end; 5. procedure TForm1.Button1Click(sender: TObject); begin testCallBack(callMe); //subscribe function in DLL end;
  • 5. Create a DLL 5 Callback in the DLL In the DLL you would also declare a function type and a procedure (or function) itself, so use it like this: type TCallBackFunction = function(sig: integer):boolean; procedure TestCallBack(clientFunc: TCallBackFunction); stdcall; var sigAlive: boolean; begin {timer stuff... set the signal...} if(clientFunc(55)) then sigalive := true; end; exports TestCallBack;
  • 6. http://max.kleiner.com/dllplus.htm 6 Export an object-reference from a DLL is one approach to get real OO-access to a DLL. The DLL must create and return the object, so the client gets the methods without encapsulating. unit income1; interface type IIncome = class public function GetIncome(const aNetto: Currency): Currency; virtual; abstract; procedure SetRate(const aPercent, aYear: integer); virtual; abstract; function queryDLLInterface(var queryList: TStringList): TStringList; virtual; abstract; end; 036_pas_includetest_EKON3.txt 036_pas_dynlib_EKON4.txt 036_pas_DLLTesting_EKON5.tx
  • 7. Solution FPC ELF32 shared object 7 32-bit EXE loads 32-bit DLL, 64-bit EXE loads 64-bit DLL. ************* Simple Sequence Diagram************** Client DLL ¦ TestCallBack(clientFunc) ¦ ¦---------------------------------------------->¦ ¦ clientFunc.callMe(sig ) ¦ ¦<----------------------------------------------¦ ¦ ¦ ¦ true (or something to return) ¦ ¦---------------------------------------------->¦ ¦ ¦ http://wiki.freepascal.org/Android_Programming http://www.softwareschule.ch/examples/440_DLL_Tutor2.txt Tutor: http://www.softwareschule.ch/download/maxbox_starter18_3.pdf
  • 8. Solution NDK The NDK is a toolset that allows you to implement parts of your app using native-code languages such as C, Pascal, Object Pascal and C++. For certain types of apps, this can be helpful so you can reuse existing code libraries written in these languages, but most apps do not need the Android NDK. Typical good candidates for the NDK are CPU-intensive workloads such as game engines, signal processing, physics simulation, and so on. When examining whether or not you should develop in native code, think about your requirements and see if the Android framework APIs provide the functionality that you need. You have to use the Android NDK to recompile the library. The ARM architecture is completely different from the x86 architecture. The system calls are different on Linux and Windows. 8 http://www.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html
  • 9. NDK Need Things If you have the src files for the DLL, try recompiling as an ELF32 shared object, then link that instead into your Android code (- below is a Windows solution): set NDK_HOME=C:Androidandroid-ndk-r9c // customize this var for your own location set LD_LIBRARY_PATH=%NDK_HOME%platformsandroid-18arch-armusrlib cd REM -- TEMPORARILY COPY SOME LIBS COMPILER MAY NEED copy %NDK_HOME%platformsandroid-18arch-armusrlibcrtbegin*.o . copy %NDK_HOME%platformsandroid-18arch-armusrlibcrtend*.o . REM -- GENERATE YOUR OBJ FILE %NDK_HOME%toolchainsarm-linux-androideabi-4.8prebuiltwindows-x86_64binarm-linux-androideabi- gcc.exe -g -I%NDK_HOME%platforms android-18arch-armusrinclude -c -fPIC YourLib.c -o YourLib.o REM -- GENERATE SHARED OBJ FROM OBJ FILE %NDK_HOME%toolchainsarm-linux-androideabi-4.8prebuiltwindows-x86_64binarm-linux-androideabi- gcc.exe -g -L%NDK_HOME%platforms android-18arch-armusrlib -shared -o YourLib_so.so YourLib_so.o REM -- finally, remove the libraries previously copied to src directory del .crtbegin*.o del .crtend*.o 9
  • 10. Optional: Create <project>/jni/Application.mk. Build your native code by running the 'ndk-build' script from your project's directory. It is located in the top-level NDK directory: cd <project> <ndk>/ndk-build I discovered that to use the build-ndk script, I don't need a real project. I created a folder project, with nothing in it except another folder jni, and put all my sources in that folder. I then created the Android.mk file and ran the script as described in the ndk docs. 10 Here's the general outline of how you work with the NDK tools: Place your native sources under <project>/jni/... Create <project>/jni/Android.mk to describe your native sources to the NDK build system http://developer.android.com/sdk/ndk/index.html
  • 11. Thanks! Links to Blocks the source is the code http://www.softwareschule.ch/maxbox.htm http://sourceforge.net/projects/maxbox http://en.wikipedia.org/wiki/Arduino http://www.softwareschule.ch/download/webofthings2013.pdf Book Patterns konkret http://www.amazon.de/Patterns-konkret-Max-Kleiner/dp/3935042469 maXbox https://github.com/maxkleiner/maXbox3/releases 11 http://max.kleiner.com/dllplus.htm http://www.softwareschule.ch/download/dlldesign_ekon9.pdf http://developer.android.com/sdk/ndk/index.html http://www.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html
  • 12. Questions? Code a World hack the earth 12 Yes, we hack… https://github.com/maxkleiner/maXbox3/releases