博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4.VS2010C++建立DLL工程
阅读量:6853 次
发布时间:2019-06-26

本文共 1944 字,大约阅读时间需要 6 分钟。

 

相关资料:

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.写入如下代码:

1 unit Unit1; 2  3 interface 4  5 uses 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7   Dialogs, StdCtrls, Buttons; 8  9 type10   TForm1 = class(TForm)11     BitBtn1: TBitBtn;12     procedure BitBtn1Click(Sender: TObject);13   private14     {
Private declarations }15 public16 {
Public declarations }17 end;18 19 var20 Form1: TForm1;21 22 23 function Add(Aint: Integer; Aint2: Integer):Integer; cdecl; external 'DBEngine.dll';24 25 26 implementation27 28 {
$R *.dfm}29 30 procedure TForm1.BitBtn1Click(Sender: TObject);31 var32 AddValue:Integer;33 begin 34 AddValue := Add(1, 2);35 Caption := IntToStr(AddValue);36 end;37 38 end.
View Code

4.F9运行就可以看到结果了。

PS:声明中不加__stdcall,采用VC默认格式__cdecl,但在Delphi中要注明调用格式为cdecl。

 

转载于:https://www.cnblogs.com/FKdelphi/p/5982220.html

你可能感兴趣的文章
laravel中的命名公约规范及relation N+1问题
查看>>
Convolution of measures and one application
查看>>
逆序对 线段树&树状数组 (重制版)
查看>>
从此错位(相减)无计算
查看>>
RESTful API 设计最佳实践
查看>>
想要成为一个人,先按那个人的要求去做,你自然就成了那个人(转)
查看>>
Codeforces Round #425 (Div. 2) - A
查看>>
mysql学习【第12篇】:数据库之视图,触发器,事务等
查看>>
hdu4982 Goffi and Squary Partition (DFS解法)
查看>>
Bash Shell 获取进程 PID
查看>>
RHEL7安装部署RabbitMQ
查看>>
关于站在移动物上的问题
查看>>
UVA 11205 The broken pedometer
查看>>
直击微软MIX11 聚焦IE10、Silverlight5、WP7
查看>>
MVC工作原理
查看>>
斐波那契数列Log(n)算法
查看>>
信息处理,分而治之-- ESFramework 使用技巧
查看>>
SQL Server 查询计划总结
查看>>
60幅精美绝伦的绘景(Matte Paintings)作品欣赏(下篇)
查看>>
解决 IE6 position:fixed 固定定位问题
查看>>