积木

No sub title

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

http://www.4ucode.com/Study/Topic/1996448

VS2008中创建DLL工程

      文件->新建->项目->visual c++->win32->win32控制台应用程序(win32项目也可以)

      填写项目名称MyDLL->确定->下一步->DLL(附加选项 对空项目打钩)->完成。

      到这里DLL工程就创建完毕了,下面新建两个文件testDLL.cpp和testDLL.h。



C++ .h 文件

#define DLL_EXPORT __declspec(dllexport) 
extern "C" DLL_EXPORT int MyMinus(int a,int b);



.cpp 文件
// testDLL.cpp : 定义 DLL 应用程序的导出函数。
//

#include "stdafx.h"


#include "testDLL.h"

int MyMinus(int a,int b)
{
 return (a-b);
}




delphi调用代码
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    edt1: TEdit;
    edt2: TEdit;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    btn1: TButton;
    lbl4: TLabel;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
const
  TestDll = 'testDLL.dll';
function MyMinus(a:Integer;b:Integer):Integer;cdecl;external TestDll;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin
  lbl4.Caption := IntToStr(MyMinus(StrToInt(edt1.Text),StrToInt(edt2.Text)));
end;

end.
posted on 2011-11-22 09:50 Jacc.Kim 阅读(1684) 评论(0)  编辑 收藏 引用 所属分类: VC / C++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理