Visual Studio writes its own dynamic-link library (DLL)

Source: Internet
Author: User

Sometimes we want to write our own library of functions to avoid repeating code, and this article describes how to write your own dynamic-link library using Visual Studio.


0, Experimental environment description:

Integrated development environment: Visual Studio 10.0

Operating system: Windows 7

Language: C + +


1. Write your own DLL

In two parts we describe how to complete writing your own DLL.

1.1, Environment construction

Describes how to use Visual Studio to build a DLL project that has additional configuration.

First, create an empty project for a DLL, as shown in:





Add two files, a header file (mydll.h), a source file (mydll.cpp), name the filename according to your needs, there is no need to write a dead file name.



Pay particular attention to whether there is something similar to what is shown in the project properties, and if there are no red box-labeled macros, add the appropriate macro, such as Mydll_export.



1.2, Code description

Add the following to the. h file:

#ifndef __my_dll_h__#define __my_dll_h__#if (defined WIN32 | | defined _WIN32 | | defined WINCE) && defined MYDLL_EX ports#  define Ab_exports __declspec (dllexport) #else #  define Ab_exports#endifab_exports void func (); #endif

In the above code, Func is the function we define ourselves.

Add the following code to the. cpp file:

#include "mydll.h" #include <iostream>void func () {  std::cout << "Hello func \ n";}

After the build command is executed, the following appears next to the build directory:



2. Test your own DLL

Add a Win32 Consol application empty project, add the CPP code file to the new project, and include the following code:

#include "mydll.h" #include <iostream>using namespace Std;int main () {  func ();  return 0;}


Then configure as shown.







Build Ctrl + F5 Execution! Execute the results as shown:



Summarize

This article mainly discusses how to use Visual Studio to create your own DLL, with examples to illustrate the process, the results show that the method in the paper is feasible.


If there is insufficient support, you are welcome to criticize correct.


Visual Studio writes its own dynamic-link library (DLL)

Related Article

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.