"Go" VS2010 creating DLL plots in C + +

Source: Internet
Author: User

Tags: dllc++2010threadlibrarycThis article has been included in:Classification:C + + (103) Author of similar articles X

    first, the creation of DLLs
    Create Project: Win32->win32 project, Name: MyDLL


    Select DLL (D) to finish.

    1. New header file testdll.h
    The testdll.h code is as follows:

    #ifndef Testdll_h_
    #define Testdll_h_
    #ifdef Mylibdll
    #define Mylibdll extern "C" _declspec (dllimport)
    #else
    #define Mylibdll extern "C" _declspec (dllexport)
    #endif
    Mylibdll int Add (int plus1, int plus2);
    Can also write like this:
    extern "C" {
    _declspec (dllexport) int Add (int plus1, int plus2);
    //};
    #endif

    2. New source file Testdll.cpp
    The Testdll.cpp code is as follows:

    #include "stdafx.h"
    #include "testdll.h"
    #include <iostream>
    using namespace Std;
    int Add (int plus1, int plus2)
    {
    int add_result = Plus1 + plus2;
    return add_result;
    }



    3. New module definition file Mydll.def
    The MYDLL.DEF code is as follows:

    LIBRARY "MyDLL"
    Exports
    ADD @1



    4. VS2010 automatically creates the Dllmain.cpp file, which defines the entry point of the DLL application.

    The Dllmain.cpp code is as follows:
    Dllmain.cpp: Defines the entry point for the DLL application.
    #include "stdafx.h"
    BOOL apientry DllMain (hmodule hmodule,
    DWORD Ul_reason_for_call,
    LPVOID lpreserved
    )
    {
    Switch (Ul_reason_for_call)
    {
    Case Dll_process_attach:
    Case Dll_thread_attach:
    Case Dll_thread_detach:
    Case Dll_process_detach:
    Break
    }
    return TRUE;
    }

    Finally, compile the build MyDLL.dll file and the MyDLL.lib file.

    1>------Started Build: Project: MyDLL, configuration: Debug Win32------

    1> Dllmain.cpp

    ========== Generation: Success 1, failure 0, latest 0, skip 0 ==========

    1>------Started Build: Project: MyDLL, configuration: Debug Win32------

    1> Stdafx.cpp

    1> Testdll.cpp

    1> MyDLL.cpp

    1> is generating code ...

    1> Creating library D:\Visual c++\ Engineering \libaray\mydll\debug\mydll.lib and Objects D:\Visual c++\ project \libaray\mydll\debug

    "Go" VS2010 creating DLL plots in C + +

    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.