This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
tutorial:dlllibrary [2018/12/25 08:20] admin [Shared Library คืออะไร] |
tutorial:dlllibrary [2019/01/04 12:04] admin [การระบุ Calling Convention] |
||
---|---|---|---|
Line 124: | Line 124: | ||
<sxh delphi;highlight: [8,13-14,20-35,42]> | <sxh delphi;highlight: [8,13-14,20-35,42]> | ||
program DynamicCalling_PIPEDLL; | program DynamicCalling_PIPEDLL; | ||
- | //This example demonstrates the simple use of static calling .dll library. | + | //This example demonstrates the simple use of static/Dynamic calling. |
//For calling convention, register is used by default. | //For calling convention, register is used by default. | ||
Line 183: | Line 183: | ||
| oldfpccall | RTR | Callee | | | oldfpccall | RTR | Callee | | ||
- | จากตารางข้างบนอธิบายถึงความต่างของแต่ละ Calling Convention คือทิศทางการใส่ค่าตัวแปร และการกำจัดค่าของตัวแปรใน Ram จะเห็นได้ว่า default, register และ pascal จะมีการใส่ค่าตัวแปรแบบ "ซ้ายไปขวา" หรือ LTR (Left-to-Right) ในขณะที่ cdecl, interupt, safecall, stdcall และ oldfpccall จะใส่ค่าตัวแปรแบบ "ขวาไปซ้าย" หรือ RTL (Right-to-Left) | + | จากตารางข้างบนอธิบายถึงความต่างของแต่ละ Calling Convention มีทั้งเรื่องทิศทางการใส่ค่าตัวแปร และการกำจัดค่าของตัวแปรใน Ram จะเห็นได้ว่า default, register และ pascal จะมีการใส่ค่าตัวแปรแบบ "ซ้ายไปขวา" หรือ LTR (Left-to-Right) ในขณะที่ cdecl, interupt, safecall, stdcall และ oldfpccall จะใส่ค่าตัวแปรแบบ "ขวาไปซ้าย" หรือ RTL (Right-to-Left) |
\\ \\ | \\ \\ | ||
**__ข้อควรระวัง__** - หากเราระบุ Calling Convention ใน .dll ไม่ตรงกับการเรียกใช้ในไฟล์ .exe ก็อาจทำให้เกิดการใส่ตัวแปรในแต่ละ Argument ของ Procedure/Function สลับกันได้ จะนำไปสู่การคำนวณที่ผิดพลาดอย่างแน่นอน | **__ข้อควรระวัง__** - หากเราระบุ Calling Convention ใน .dll ไม่ตรงกับการเรียกใช้ในไฟล์ .exe ก็อาจทำให้เกิดการใส่ตัวแปรในแต่ละ Argument ของ Procedure/Function สลับกันได้ จะนำไปสู่การคำนวณที่ผิดพลาดอย่างแน่นอน | ||
\\ \\ | \\ \\ | ||
- | **__หมายเหตุ__** - การไม่ระบุ Calling Convention นั้น จะหมายถึงการเรียกใช้งานแบบ default ซึ่งตัว default สำหรับ FPC คือ register | + | **__หมายเหตุ__** - การไม่ระบุ Calling Convention นั้น จะหมายถึงการเรียกใช้งานแบบ default ซึ่ง default calling convention สำหรับ FPC คือ register |
<hidden Example-4: Static Calling .dll Library using stdcall as calling convention> | <hidden Example-4: Static Calling .dll Library using stdcall as calling convention> | ||
**ตัวอย่าง** การเรียก Library ชื่อว่า Pipe เพื่อเก็บฟังก์ชั่นคำนวณหาพื้นที่หน้าตัดท่อ\\ | **ตัวอย่าง** การเรียก Library ชื่อว่า Pipe เพื่อเก็บฟังก์ชั่นคำนวณหาพื้นที่หน้าตัดท่อ\\ |