Creation and invocation of dynamic link libraries in C + +

Source: Internet
Author: User

Steps to create a dynamic connection library:

First, create NON-MFC DLL dynamic link library

1, open file-> new-> project option, select Win32 dynamic-link library->sample Project

-> Project Name: Dlldemo

2, a new one. h file DllDemo.h

#ifdef Dlldemo_exports

#define DLLAPI __declspec (dllexport)

#else

#define DLLAPI __declspec (dllimport)

extern "C"//compiled as is

{

Dllapi int __stdcall Max (int a,int b); __stdcall enables the ability to invoke APIs within non-C + + languages

}

#endif

3, import DllDemo.h file in DllDemo.cpp file, and implement Max (Int,int) function

#include "DllDemo.h"

Dllapi int __stdcall Max (int a,int b)

{

if (a==b)

return NULL;

else if (a>b)

return A;

Else

return b;

}

4, compile the program to generate dynamic connection library

Create a dynamic connection library DllDemo.dll with a. def file.

1, delete the Dlldemo project in the DllDemo.h file.

2, in the DllDemo.cpp file header, delete #include DllDemo.h statement.

3. Add a text file to the project, name it dlldemo.def and write the following statement:

LIBRARY Mydll

Exports

max@1

4, compile the program to generate dynamic Connection library.

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.