"Go" VS2010 creating DLL plots in C + +

Source: Internet
Author: User

Reprint Address: http://blog.csdn.net/g710710/article/details/7255744

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



The role of DEF files is to export the function entry of the DLL so that the program can access it correctly because it is already defined using _declspec (dllexport) or _declspec (Dllinport), so it is not required. Furthermore, using the VS2010 learning version does not seem to have a DEF file type definition, so you can also consider canceling the use.

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_thread_attach:
case Dll_thread_detach:
case Dll_process_detach:
  break;
return TRUE;
/span>

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 + +

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.