In VC ++, if a DLL is generated, the. Def file is not used. You only need to add _ declspec (dllexport) before the Function Definition of VC ++. However, using _ declspec (dllexport) is different from using a. Def file. If the DLL is provided to VC ++ users, you only need to provide the. Lib generated during DLL compilation to users. It can easily call your DLL. However, if the DLL is used by VB, Pb, and Delphi users, it may cause a small problem. Because VC ++ converts the name of a function declared by _ declspec (dllexport), the following functions are provided:
_ Declspec (dllexport) int _ stdcall iswinnt ()
It will be converted to iswinnt @ 0, so that you must declare in VB as follows:
Declare function iswinnt lib "My. dll" alias "iswinnt @ 0" () as long
The number following @ may vary depending on the parameter type. This is obviously inconvenient. If you want to avoid this conversion, you must use the. Def file method.
The number after exports can be left blank, and the system will automatically allocate a number. For VB, Pb, and Delphi users, the call method by name is usually used. This number does not matter, but for VC connected by. Lib Program For example, it is not called by name, but by this number, so it is best to give it. For example:
Exports
Test @ 1
Vc dll, the method called by Delphi:
/// K9rtexpr. h
Extern "C" _ decdll
Unsigned int _ stdcall k9rtsysinterrupt (INT ninterrupttag );
Extern "C" _ decdll
Unsigned int _ stdcall k9rtsysexprm (unsigned int nmoduletag,
Float ftimeout,
Void * ptestpar,
Void * presultpar
);
// K9rtexpr. cpp
# Include "k9rtexpr. H"
# Include "rtctrl. H"
Extern "C" _ decdll
Unsigned int _ stdcall k9rtsysinterrupt (INT ninterrupttag)
{
Return crelaytestcontrol: instance ()-> interrupttest (ninterrupttag );
}
Extern "C" _ decdll
Unsigned int _ stdcall k9rtsysexprm (unsigned int nmoduletag,
Float ftimeout,
Void * ptestpar,
Void * presultpar
)
{
Return crelaytestcontrol: instance ()-> relaytest (
Nmoduletag, ftimeout, ptestpar, presultpar );
}
/// K9rtexpr. Def
Library "k9rtexpr"
Description k9rtexpr Windows dynamic link library'
Exports
K9rtsysinterrupt
K9rtsysexprm
; Explicit exports can go here
// Delphi call File
Unit interfacefunc;
Interface
Uses
Unitdata, types;
Function k9rtsysexprm (nmoduletag: integer;
Utimeout: integer;
Ptestpar: pointer;
Presultpar: pointer): integer; stdcall;
Function k9rtsysinterrupt (ninterrupttype: integer): integer; stdcall;
Implementation
Const dllpath = 'rtbsexpr. dll ';
Function k9rtsysexprm; External dllpath name 'experimentrelaytest ';
Function k9rtsysinterrupt; External dllpath name 'interruptrelaytest ';
End.