Generating DLL files under VS2010 environment

Source: Internet
Author: User
Tags knowledge base visual studio 2010

VS2010 Build DLL file 1, create a new Win32 project, select the DLL project, such as:

2, add header files and CPP files separately
#ifndef Lib_h
#define Lib_h
extern "C" int _declspec (dllexport) Add (int x,int y); External functions declared as C-compile, link-way
#endif # include "StdAfx.h"
int add (int x,int y)
{
return x+y;
}3, create a new Win32 console project, add the header file, and then write the following code in the main function:
#include "stdafx.h"
using namespace Std;
int _tmain (int argc, _tchar* argv[])
{
typedef int (*lpaddfun) (int,int);//macro defines function pointer type
HINSTANCE Hinst=null;
Lpaddfun Addfun; function pointers
Hinst=::loadlibrarya ("C:\\users\\administrator\\documents\\visual Studio 2010\\projects\\win32study\\debug\\test _1.dll ");
if (hinst==null)
{
printf ("Load mydll. DLL fail!\n ");
return 0;
}
Else
{
Addfun= (Lpaddfun) GetProcAddress (HInst, "add");
if (addfun!=null)
{
int Result=addfun (2,3);
cout<<result<<endl;
GetChar ();
}
}
FreeLibrary (HInst);
return 0;
}4, running results such as:

Posted on 2012-02-03 21:21 Gavin Read (3777) Comments (0) Edit collection reference belongs to Category: Compile


Find good programmers, just in the blog park
Title
Name
Home
Verification Code *
Content (after a commit failure, you can recover the content you just submitted by "Recover last Commit")
Remember Me?
Sign in using advanced comments new user registration back to top restore last commit
[can be submitted directly using the Ctrl+enter key]
"Recommended" Super 500,000 line VC + + Source: Large configuration industrial control, power simulation CAD and GIS Source Library
Related articles:
  • Program generation Process
  • Building DLL Modules
  • Compiler integration Tools
  • The stages of the compiler
  • SOURCE program Analysis
  • The predecessor and successor of the compilation
  • ANALYSIS--Comprehensive model
  • Compiler
  • Throughout the construction of DLLs
  • Address space for DLLs and processes
Site Navigation: Blog Park It news Blogjava Knowledge Base programmer recruitment Management


Generating DLL files under VS2010 environment

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.