最简单的delphi加载C++dll实例
2013-06-11 08:17
253 查看
C++的dll:
#ifndef _DLL_FOR_DEL_H_
#define _DLL_FOR_DEL_H_
extern "C"
{
_declspec(dllexport)int mult();
};
#endif
---------
#include "dllfordel.h"
int mult()
{
return 5*6;
}
================================delphi==========================
unit CPlusDllTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
CplusFuc=function():Integer;stdcall;
TForm1 = class(TForm)
lbl1: TLabel;
edt1: TEdit;
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Func:CplusFuc;
hMhd:Thandle ;
ret:Integer;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
hMhd:=LoadLibrary('dllfordel.dll');
if hMhd=null then
begin
Application.MessageBox('加载C++ dll失败',0)
end
else
begin
// Application.MessageBox('加载C++ dllsucess','加载dll',MB_OK) ;
@Func:=GetProcAddress(hMhd,'mult');
ret:=Func();
edt1.Text:=IntToStr(ret);
end;
end;
//end;
//end;
procedure TForm1.btn2Click(Sender: TObject);
begin
edt1.Text:='';
end;
end.
#ifndef _DLL_FOR_DEL_H_
#define _DLL_FOR_DEL_H_
extern "C"
{
_declspec(dllexport)int mult();
};
#endif
---------
#include "dllfordel.h"
int mult()
{
return 5*6;
}
================================delphi==========================
unit CPlusDllTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
CplusFuc=function():Integer;stdcall;
TForm1 = class(TForm)
lbl1: TLabel;
edt1: TEdit;
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Func:CplusFuc;
hMhd:Thandle ;
ret:Integer;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
hMhd:=LoadLibrary('dllfordel.dll');
if hMhd=null then
begin
Application.MessageBox('加载C++ dll失败',0)
end
else
begin
// Application.MessageBox('加载C++ dllsucess','加载dll',MB_OK) ;
@Func:=GetProcAddress(hMhd,'mult');
ret:=Func();
edt1.Text:=IntToStr(ret);
end;
end;
//end;
//end;
procedure TForm1.btn2Click(Sender: TObject);
begin
edt1.Text:='';
end;
end.
相关文章推荐
- c++ DLL 简单接口实例
- Silverlight实用窍门系列:22.Silverlight使用WebService调用C++,Delphi编写的DLL文件【实例源码下载】
- C++之lib和dll实例及简单分析
- Silverlight实用窍门系列:22.Silverlight使用WebService调用C++,Delphi编写的DLL文件【实例源码下载】
- Delphi 用DLL实现插件的简单实例
- linux下c++使用ncurses库的一个简单实例
- C++多线程编程简单实例
- 在Delphi中动态调用C++的DLL
- C++多线程编程简单实例
- 最简单的0-1背包问题c++代码实例及运行结果
- C++基于TCP/IP简单的客户端、服务器通信程序实例
- VC++MFC 简单的DLL加载动态链接库
- c++ clr编译dll在c#调用时出现“试图加载不正确的格式”“找不到dll”错误的解决
- C#调用C++生成的DLL(实例1)
- c#调用C++ dll 报未将对象引用到设置对象的实例 的解决方案
- c++显式加载dll并使用DLL的类
- lua 调用C++ DLL函数简单实例
- 一个简单的c++模板开发实例
- LinuxC/C++编程基础(20) 使用boost::asio搭建服务器简单实例
- 用C#加载C++编写的win32dll