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