c++ DLL 文件,建议用最简单的c++编辑工具。不会加入很多无关的DLL文件。本人用codeblocks+mingw。不像

VS2010,DLL编译成功,调用的时候会提示缺其他DLL。 系统生成的main.h和main.cpp

#ifndef __MAIN_H__

#define __MAIN_H__

#include <windows.h>

/* To use this exported function of dll, include this header

* in your project.

*/

#ifdef BUILD_DLL

#define DLL_EXPORT __declspec(dllexport)

#else

#define DLL_EXPORT __declspec(dllimport)

#endif

#ifdef __cplusplus

extern "C"

{

#endif

int DLL_EXPORT Add(int plus1, int plus2); //导出函数Add

#ifdef __cplusplus

}

#endif

#endif // __MAIN_H__

#include "main.h"

// a sample exported function

int DLL_EXPORT Add(int plus1, int plus2) //导出函数Add 的实现

{

int add_result = plus1 + plus2;

return add_result;

}

extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)

{

switch (fdwReason)

{

case DLL_PROCESS_ATTACH:

// attach to process

// return FALSE to fail DLL load

break;

case DLL_PROCESS_DETACH:

// detach from process

break;

case DLL_THREAD_ATTACH:

// attach to thread

break;

case DLL_THREAD_DETACH:

// detach from thread

break;

}

return TRUE; // succesful

}

只有一个简单函数Add,就是为了测试delphi能不能成功调用

delphi 用按钮加入调用函数

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

btn1: TButton;

Edit1: TEdit;

procedure btn1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

_DLLMoudle: THandle;

_GetAdd:function (plus1:Integer; plus2:Integer):Integer;cdecl;

//动态调用,不要少了cdecl,百度看到是因为dll调用函数,传参数的差异

// function Add( plus1:Integer; plus2:Integer):Integer;

// stdcall; external 'MyDll.dll' name 'Add';

// 静态调用,静态调用有问题,还是声明stdcall 再C++种声明导出函数的原因

// 把stdcall 改为cdecl 就可以用静态调用了。具体C++声明函数和delphi对应关系看后面

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);

var

l_int : integer;

begin

try

_DLLMoudle := Loadlibrary('MyDLL.dll');

ShowMessage('加载成功!!!');

except

ShowMessage('加载失败!!!');

Exit;

end;

if _DLLMoudle > 32 then

begin

try

begin

@_GetAdd:=GetProcAddress(_DLLMoudle,'Add');

l_int:=_GetAdd(5,6);

Edit1.Text:=IntToStr(l_int);

end

except

ShowMessage('有问题!');

end;

end;

// l_int:=Add(1,3);

// Edit1.Text:=IntToStr(l_int);

end;

end.

C++的参数调用方式 对应的DELPHI的参数调用方式

_declspec cdecl

WINAPI,CALLBACK stdcall

PASCAL pascal

以上请多试一下。我也是测试很多次才成功的。以后核心逻辑用C++。

Delphi动态调用C++写的DLL的更多相关文章

  1. 发现个delphi调用vc写的Dll中包括pchar參数报错奇怪现象

    发现个delphi调用vc写的Dll中包括pchar參数奇怪现象 procedure中的第一行语句不能直接调用DLL的函数,否则会执行报错,在之前随意加上条语句就不报错了奇怪! vc的DLL源代码地址 ...

  2. Delphi7程序调用C#写的DLL解决办法(转)

    近来,因工作需要,必须解决Delphi7写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行:    编写C#dll的方法都一样,首先在vs2005中创建一个 ...

  3. Delphi7程序调用C#写的DLL解决办法

     近来,因工作需要,必须解决Delphi7写的主程序调用C#写的dll的问题.在网上一番搜索,又经过种种试验,最终证明有以下两种方法可行:    编写C#dll的方法都一样,首先在vs2005中创建一 ...

  4. c++ c# java 调用 c++ 写的dll

    1. vs 中新建win32 dll 项目   testdll 添加实现文件       test.cpp #include "stdafx.h" #include <ios ...

  5. C#动态调用C++编写的DLL函数

    C#动态调用C++编写的DLL函数 动态加载DLL需要使用Windows API函数:LoadLibrary.GetProcAddress以及FreeLibrary.我们可以使用DllImport在C ...

  6. Delphi动态调用Java的WebService 转

    Delphi动态调用Java的WebService —— 基于“Axis2发布WebService例子(HelloWorld)” uses ComObj; var WsObject: Variant; ...

  7. c++调用c#写的DLL

    c++调用c#写的DLL: 此文章演示了建立c#的dll: c++建立工程,引入dll: 不能解决的问题: 指定dll的路径,在代码里面直接写 #using "xxx.dll" 必 ...

  8. QT调用C#写的Dll

    参见: https://blog.csdn.net/weixin_42420155/article/details/81060945 C#写的dll是没有dllMain入口函数的,是一种中间语言,需要 ...

  9. 【转载】java调用C++写的DLL

    用java调用C++写的DLL一直以来都是一个比较麻烦但又很常见的问题. 我们知道,使用 JNI 调用 .dll/.so 共享类库是非常非常麻烦和痛苦的. 如果有一个现有的 .dll/.so 文件,如 ...

随机推荐

  1. Sebastian Ruder : NLP 领域知名博主博士论文面向自然语言处理的神经网络迁移学习

    Sebastian Ruder 博士的答辩 PPT<Neural Transfer Learning for Natural Language Processing>介绍了面向自然语言的迁 ...

  2. python学习之----导航树

    findAll 函数通过标签的名称和属性来查找标签 .但是如果你需要通过标签在文档中的位 置来查找标签,该怎么办?这就是导航树(Navigating Trees)的作用.在第1 章里,我们 看过用单一 ...

  3. MVC Html辅助方法DropDownList的简单使用、连接MYSQL数据库用自定义model类接收

    附上启发链接:https://www.cnblogs.com/CreateMyself/p/5424894.html [HttpGet] public ActionResult Edit(int id ...

  4. vue2.0 slot用法

    学习vue.js也有一段时间了,关于slot这一块,也看了不少次了,总感觉有点迷迷糊糊,不知其然也不知其所以然,抽出一段完整的时间,再一次仔细学习.稍微有点理解了,在此稍作记录,好记性不如烂笔头嘛! ...

  5. 【Git+Docker】Docker初期学习认识和安装配置详解

    Docker: 特性: 1.以应用为中心 2.自动化构建 3.版本控制 4.组件重用 5.镜像共享 6.工具生态系统 具体后续学习 优势: 1.文件系统隔离 2.进程隔离 3.网络隔离 4.资源隔离和 ...

  6. 剑指Offer(三):从尾到头打印链表

    说明: 1.本系列是根据<剑指Offer>这个系列做的一个小笔记. 2.直接动力是因为师兄师姐找工作很难,而且机械出生的我面试算法更难. 3.刚开始准备刷LeetCode.LintCode ...

  7. <Linux> 文件夹右下角有锁,解锁

    sudo chown -R $USER 文件夹路径 例如:sudo chown -R $USER ~/scala

  8. http 文件传输

    http 文件传输 https://www.zhihu.com/question/58118565 转载自:http://www.voidcn.com/article/p-rpdhbjib-m.htm ...

  9. 43.纯 CSS 绘制一个充满动感的 Vue logo

    原文地址:https://segmentfault.com/a/1190000015177284 感想: 又有点回到boder的三角形 HTML code: <div class="v ...

  10. http://www.cnblogs.com/hanshuhe/archive/2012/08/30/vss.html

    http://www.cnblogs.com/hanshuhe/archive/2012/08/30/vss.html