How is the DLL developed in Delphi implicitly called by other development languages?

Source: Internet
Author: User


How is the DLL developed in Delphi implicitly called by other development languages?

I used Delphi to develop the "IAPWS-IF97/ifc67 Water and Steam computation software package". To facilitate other developers
I developed a dynamic link library (DLL) for further development of thermal energy and power analysis software ). Other developers are not professional
Sequence designers are not good at using explicit dynamic calling of Dynamic Link Libraries (although flexible but cumbersome) to help them make good use of them
I developed the "dynamic link library for Water and Steam computation", and I started to be popular with various modernProgramDesign Language (VC ++,
C ++ builder, VC #, C # builder, VB, VB. NET, Delphi, and Delphi. Net) implicitly calls
And made some progress.

It is reasonable to use DLL based on the following points:
1) different programs use the same DLL, so you only need to load the DLL once in the memory, saving the memory overhead.
2) When some content needs to be upgraded, you only need to change the DLL to use the DLL, instead of the entire process.
Are all updated.
3) because the DLL is independent from the language, when people with different language habits develop a large project together
Using DLL facilitates communication between program systems. Of course, the DLL developed by Delphi can also be used in languages such as VB and C ++.

 

1. Dynamic Connection Library Construction

DLL project created in DelphiSource codeThe parts are:

Library wspif97;

Uses
Sysutils,
Registry,
Classes,
Math;

{$ R *. Res}

Const
// Initialize coefficients for region 4
// Initialize the coefficients and exponent of the basic formula of Area 4
Nreg4: array [1 .. 10] of double =
(
1167.0521452767,-724213.16703206,-17.073846940092, 12020.82470247,-3232555.0322333,
14.91510861353,-4823.2657361591, 405113.40542057,-0.23855557567849, 650.17534844798
);

// Known temperature (K), calculate the corresponding saturated pressure (bar)
// P ^ *: = 1 Mpa: = 10 bar t ^ *: = 1 K
Function t2p (const temperature: Double): Double;
VaR
Del, Aco, BCO, CCO: Double;
Begin
DEL: = temperature + nreg4 [9]/(temperature-nreg4 [10]);
ACO: = del * del + nreg4 [1] * del + nreg4 [2];
BCO: = nreg4 [3] * del + nreg4 [4] * del + nreg4 [5];
CCO: = nreg4 [6] * del + nreg4 [7] * del + nreg4 [8];
Result: = power (2 * CCO/(-BCO + power (BCO * bco-4 * ACO * CCO, 0.5), 4) * 10;
End;

Procedure t2p97 (const T: Double; var P: Double; var range: integer); export; stdcall;
Begin
P: = t2p (t + t000c)/10; // change the temperature unit to k, and then change the pressure unit bar to MPa.
End;

Exports t2p97;

End.

The Call Protocol I used is stdcall, and the function exported from the DLL is t2p97. Dynamic Link Library generated after compilation
Wspif97.dll.

Ii. Dynamic Connection Library call

2.1 Delphi

You only need to add the following function declaration to the unit that calls the wspif97.dll dynamic link library.

// Determine the saturated pressure (MPa) at a known temperature (℃ )?
Procedure t2p97 (const T: Double; var P: Double; var range: integer); stdcall; External 'wspif97. dll ';

2.2 delphi. net

You only need to add the following function declaration to the unit that calls the wspif97.dll dynamic link library.

// Determine the saturated pressure (MPa) at a known temperature (℃ )?
[Dllimport ('wspif97. dll ', callingconvention = callingconvention. stdcall, charset = charset. Unicode, preservesig = false)]
Procedure t2p97 (const T: Double; var P: Double; var range: integer );
External;

2.3 C ++ Builder

1.use implib.exe of borland.exe to generate the corresponding import/export warehouse (wspif97.lib). The command format is:

Implib wspif97.lib wspif97.dll

2. Write the corresponding header file wspif97.h

# Define import_type extern "C" _ declspec (dllimport) _ stdcall

// Determine the saturated pressure (MPa) at a known temperature (℃ )?
Import_type void t2p97 (double T, double & P, Int & range );

3. directly add the imported file (wspif97.lib) and the header file (wspif97.h) to the corresponding project,
In the unit to be called # include this header file (wspif97.h!

2.4 C # Builder

1. Write a class file (wspif97.cs)

Namespace wasp
{
Public class wspif97
{
// Known temperature (℃), saturated pressure (MPa)
[Dllimport ("wspif97", entrypoint = "t2p97")]
Public static extern void t2p97 (double T, ref Double P, ref int range );
}
}

2. Add the class file (wspif97.cs) to the corresponding project, and reference the class file name in the unit that needs to call the function.
(Using WASP!

2.5 VB

You only need to add the following function declaration to the VB project that calls the wspif97.dll dynamic link library.

Rem known temperature (℃), saturated pressure (MPa)
Private declare sub t2p97 lib "wspif97.dll" (byval T as double, byref P as double,
Byref range as integer)

2.6 VB. NET

1. Write the class file wspif97.vb.

Imports system. runtime. interopservices

Public class wspif97
What is the known temperature (℃) of REM to obtain the saturated pressure (MPa )?
Declare auto sub t2p97 lib "wspif97.dll" (byval T as double, byref P as double,
Byref range as integer)
End Class

2. Add the wspif97.vb class file to the corresponding project!

2.7 VC

Microsoft does not provide a tool to generate imported lib files through DLL files.
Compile an empty DLL project with the same name to generate the corresponding imported lib file.

1. Write the def file wspif97.def.

Library wspif97.dll

Exports
T2p97

2. Compile the wspif97.cpp file.

# Include "stdafx. H"
Bool apientry dllmain (handle hmodule,
DWORD ul_reason_for_call,
Lpvoid lpreserved
)
{
Return true;
}

// Known temperature (℃), saturated pressure (MPa)
Extern "C" Void _ stdcall t2p97 (double T, double & P, Int & range ){}

3. Compile wspif97.cpp and wspif97.def to generate the corresponding import/export file wspif97.lib.

4. Write the corresponding header file wspif97.h.

# Pragma comment (Lib, "wspif97.lib ")

# Define import_type extern "C" _ declspec (dllimport)

// Known temperature (℃), saturated pressure (MPa)
Import_type void _ stdcall t2p97 (double T, double & P, Int & range );

5. Add the imported and imported file (wspif97.lib) and header file (wspif97.h) to the corresponding project,
In the unit to be called # include the header file (wspif97.h!

2.8 VC. net

1. Write the header file wspif97.h.

// Determine the saturated pressure (MPa) at a known temperature (℃ )?
[Dllimport ("wspif97.dll")] extern void t2p97 (double T, double & P, Int & range );

2. directly add the header file (wspif97.h) to the corresponding project and # include the header file in the unit to be called.
(Wspif97.h!

2.9 VC #

1. Write a class file (wspif97.cs)

Using system;
Using system. runtime. interopservices;

Namespace wasp
{
Public class wspif97
{
// Determine the saturated pressure (MPa) at a known temperature (℃ )?
[Dllimport ("wspif97", entrypoint = "t2p97")]
Public static extern void t2p97 (double T, ref Double P, ref int range );
}
}

2. Add the class file (wspif97.cs) to the corresponding project, and reference the class file name in the unit that needs to call the function.
(Using WASP!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.