4.VS2010C++建立DLL工程
2016-10-20 20:03
155 查看
相关资料:
http://blog.csdn.net/jshayzf/article/details/23608705 http://blog.csdn.net/huang_xw/article/details/7524359
实际操作:
1.文件->新建->项目->Win32->Win32项目->写入名字"DBEngine"->确定->下一步->选择"DLL"->完成。
2.生成->生成解决方案->"DLL\DBEngine\Debug\"下面就有出现.dll文件了。
3.头文件->右击->添加->新建项->Visual C++->代码->头文件(.h)->写入名字"DataAccess.h"->添加。
代码:
#ifndef DataAccess_H_
#define DataAccess_H_
#ifdef DBEngine
#define DBEngine extern "C" _declspec(dllimport)
#else
#define DBEngine extern "C" _declspec(dllexport)
#endif
DBEngine int Add(int plus1, int plus2);
#endif
4.源文件->右击->添加->新建项->Visual C++->代码->C++文件(.cpp)->写入名字"DataAccess.cpp"->添加。
代码:
#include "stdafx.h"
#include "DataAccess.h"
#include <iostream>
using namespace std;
int Add(int plus1, int plus2)
{
int add_result = plus1 + plus2;
return add_result;
}
5.源文件->右击->添加->新建项->Visual C++->代码->模块定义文件(.def)->写入名字"DataAccess.def"->添加。
代码:
LIBRARY "DBEngine"
EXPORTS
Add @1
6.VS2010自动定义好了DLL入口。
7.生成->生成解决方案->"DLL\DBEngine\Debug\"就出现新的.dll文件与.lib了。
//***************************************Delphi调用DLL**************************************//
1.新建一个Delphi工程。
2.放入DLL。
3.写入如下代码:
View Code
4.F9运行就可以看到结果了。
PS:声明中不加__stdcall,采用VC默认格式__cdecl,但在Delphi中要注明调用格式为cdecl。
http://blog.csdn.net/jshayzf/article/details/23608705 http://blog.csdn.net/huang_xw/article/details/7524359
实际操作:
1.文件->新建->项目->Win32->Win32项目->写入名字"DBEngine"->确定->下一步->选择"DLL"->完成。
2.生成->生成解决方案->"DLL\DBEngine\Debug\"下面就有出现.dll文件了。
3.头文件->右击->添加->新建项->Visual C++->代码->头文件(.h)->写入名字"DataAccess.h"->添加。
代码:
#ifndef DataAccess_H_
#define DataAccess_H_
#ifdef DBEngine
#define DBEngine extern "C" _declspec(dllimport)
#else
#define DBEngine extern "C" _declspec(dllexport)
#endif
DBEngine int Add(int plus1, int plus2);
#endif
4.源文件->右击->添加->新建项->Visual C++->代码->C++文件(.cpp)->写入名字"DataAccess.cpp"->添加。
代码:
#include "stdafx.h"
#include "DataAccess.h"
#include <iostream>
using namespace std;
int Add(int plus1, int plus2)
{
int add_result = plus1 + plus2;
return add_result;
}
5.源文件->右击->添加->新建项->Visual C++->代码->模块定义文件(.def)->写入名字"DataAccess.def"->添加。
代码:
LIBRARY "DBEngine"
EXPORTS
Add @1
6.VS2010自动定义好了DLL入口。
7.生成->生成解决方案->"DLL\DBEngine\Debug\"就出现新的.dll文件与.lib了。
//***************************************Delphi调用DLL**************************************//
1.新建一个Delphi工程。
2.放入DLL。
3.写入如下代码:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons; type TForm1 = class(TForm) BitBtn1: TBitBtn; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; function Add(Aint: Integer; Aint2: Integer):Integer; cdecl; external 'DBEngine.dll'; implementation {$R *.dfm} procedure TForm1.BitBtn1Click(Sender: TObject); var AddValue:Integer; begin AddValue := Add(1, 2); Caption := IntToStr(AddValue); end; end.
View Code
4.F9运行就可以看到结果了。
PS:声明中不加__stdcall,采用VC默认格式__cdecl,但在Delphi中要注明调用格式为cdecl。
相关文章推荐
- 在VS2010 C++中调试DLL工程的方法
- 在VS2010 C++中调试DLL工程的方法
- VS2010 C++中调试DLL工程
- 在VS2010 C++中调试DLL工程的方法
- 在VS2010 C++中调试DLL工程的方法
- 在VS2010 C++中调试DLL工程的方法
- 用VS2010建立解决方案,用于生成多个Dll的项目 .
- 在C#工程中调用C++的DLL
- c++建立DLL 及c# 调用
- C++ win32工程如何封装成DLL。
- ICE VS2010 C++ DLL 版本
- VS2005建立和调试基于C++的DLL项目
- 在vs2010 添加Gtest 测试框架X86 到x64 工程建立: 步骤 1. 先编译Gtest源码,生成DEBUG 版本"gtestd.lib"与RELEASE版本"gtest.lib"。此处不明
- windwos 7和vs2010 c++ 下编译工程,出现错误fatal error C1189
- C++6.0,结果在新建工程时提示缺少这个SHSQL.DLL,要求重新安装
- VS2010中 C++创建DLL图解
- Pro Engineer Pro/Toolkit dll工程二次开发设置(Pro Engineer 3.0+Visual Studio 2005(C++))
- 建立C++的dll
- 建立 ATL DLL 工程
- 用VS2010建立解决方案,用于生成多个Dll的项目