Delphi调用c++写的dll (me)
unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type
TForm1 = class(TForm)
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; function add(a:integer;b:integer):integer;cdecl;external 'mydllForDelphi.dll' ;
function sub(a:integer;b:integer):integer;cdecl;external 'mydllForDelphi.dll' ; implementation {$R *.dfm} //mydllForDelphi.dll c++写的dll中的代码
// extern "C" __declspec(dllexport) int add(int a, int b)
//{
// return (a + b);
//}
//
//extern "C" __declspec(dllexport) int sub(int a, int b)
//{
// return (a - b);
//} procedure TForm1.btn1Click(Sender: TObject);
begin
self.caption:= inttostr(add(,));
self.caption:=self.caption+'///' +inttostr(sub(,));
end; procedure TForm1.btn2Click(Sender: TObject);
// function add(a:integer;b:integer):integer;cdecl;external 'mydllForDelphi.dll' ;
type
TIntFunc=function(a:integer;b:integer):integer;cdecl; //cdecl 不能少
var
Th: Thandle;
Tf:TIntFunc;
Tp,tp2:TFarProc ;
begin
Th:= loadlibrary('mydllForDelphi.dll');
if Th > then
try
Tp:=GetProcAddress(Th, PChar('add'));
if Tp<>nil then
begin
Tf:=TIntFunc(Tp);
Self.Caption:=IntToStr(Tf(,)); {调用TestC函数}
end; Tp2:=GetProcAddress(Th, PChar('sub'));
if Tp2<>nil then
begin
Tf:=TIntFunc(Tp2);
Self.Caption:=Self.Caption+'|||'+IntToStr(Tf(,)); {调用TestC函数}
end; finally
freelibrary(th);
end; end; end.
Delphi调用c++写的dll (me)的更多相关文章
- 发现个delphi调用vc写的Dll中包括pchar參数报错奇怪现象
发现个delphi调用vc写的Dll中包括pchar參数奇怪现象 procedure中的第一行语句不能直接调用DLL的函数,否则会执行报错,在之前随意加上条语句就不报错了奇怪! vc的DLL源代码地址 ...
- Delphi调用C++写的dll示例
最近做一个读市民卡的项目,读卡器公司提供的读市民卡dll是用C++写的. 下面记录一些自己的心得,供需要的朋友参考. 声明dll函数要加上stdcall关键字,否则可能会报地址非法的错误. 代码: u ...
- Delphi 调用C/C++的Dll(stdcall关键字, 会导致函数名分裂. 此时函数名变成_stdadd@8)
delphi调用C++写的Dll, 当然这个Dll要求是非MFC的Dll, 这样子才能被delphi调用. 根据C++定义函数的情况, Delphi有不同的相对应的处理方法.1. 声明中不加__std ...
- Delphi7程序调用C#写的DLL解决办法(转)
近来,因工作需要,必须解决Delphi7写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行: 编写C#dll的方法都一样,首先在vs2005中创建一个 ...
- Delphi7程序调用C#写的DLL解决办法
近来,因工作需要,必须解决Delphi7写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行: 编写C#dll的方法都一样,首先在vs2005中创建一 ...
- Delphi 调用C# 编写的DLL方法
近来,因工作需要,必须解决Delphi写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行: 编写C#dll的方法都一样,首先在vs2005中创建一个“ ...
- c++ c# java 调用 c++ 写的dll
1. vs 中新建win32 dll 项目 testdll 添加实现文件 test.cpp #include "stdafx.h" #include <ios ...
- c++调用c#写的DLL
c++调用c#写的DLL: 此文章演示了建立c#的dll: c++建立工程,引入dll: 不能解决的问题: 指定dll的路径,在代码里面直接写 #using "xxx.dll" 必 ...
- QT调用C#写的Dll
参见: https://blog.csdn.net/weixin_42420155/article/details/81060945 C#写的dll是没有dllMain入口函数的,是一种中间语言,需要 ...
随机推荐
- 6 —— node —— 响应一个完整的页面
const http = require('http'); const fs = require('fs'); const server = http.createServer(); server ...
- Python+Selenium中级篇之8-Python自定义封装一个简单的Log类《转载》
Python+Selenium中级篇之8-Python自定义封装一个简单的Log类: https://blog.csdn.net/u011541946/article/details/70198676
- ActiveMQ持久化机制和JMS可靠消息
1.ActiveMQ持久化机制 1.1 JDBC将数据持久化到数据库 1.2 AMQ生成日志文件 1.3 KahaDB:本次磁盘生成数据文件(默认) 1.4 LevelDB:谷歌K/V数据库 1.5 ...
- SLAM的评测工具evo
遇到的问题 今天用orbslam2跑euroc数据集,将结果和真实轨迹用evo测评,发现差别特别大: evo_traj tum data.tum CameraTrajectory.txt --plot ...
- 用 Python监控了另一半的每天都在看的网站,我发现了一个秘密
阅读文本大概需要 5 分钟. ! 需求: (1) 获取你对象chrome前一天的浏览记录中的所有网址(url)和访问时间,并存在一个txt文件中 (2)将这个txt文件发送给指定的邮箱地址(你的邮 ...
- 146-PHP 使用<<<和HTML混编(二)
<?php $html=<<<HTM1 <title>PHP输出HTML代码</title> <body> <a href=#> ...
- ubuntu12.04安装JDK8
系统里已经有jdk1.6,下载并解压jdk后,按照网上的教程(bash.bashrc)没成功. sudo update-alternatives --install /usr/bin/java jav ...
- Windows + Python + flup + flask + fastcgi + Nginx配置
Nginx配置 # HTTPS server { listen ssl; server_name kvaccount.xx.io; ssl_certificate "C:/xx/conf/s ...
- sqlserver 联接查询的一些注意点
1.内连接的安全性 (1) inner join 是ANSI SQL-92 语法.等值联接是ANSI SQL-89 的语法 ,两者已相同方式解释.在性能上没有差别 (2)但是强烈建议使用ANSI SQ ...
- zoj 2314Reactor Cooling
秘制神奇上下界网络流%%% 什么什么有(木)源汇可行流什么的,,看不懂(一下纯属个人sb言论) 看了半天知道点,一个点u,从S连到u的流量是全部流入u的下界,u到T是全部流出u的下界和.(进去出来的约 ...