_ Declspec (dllexport) and. Def files

Source: Internet
Author: User

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.

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.