小编Jos*_*eMG的帖子

使用带FreePascal的C/C++ DLL

首先,我使用Mingw 4.8作为代码中的C++ DLL的编译器:块13.12和Lazarus 1.4.2用于处理pascal代码.(windows 7)

我需要在c ++或c中生成一个可以从pascal程序调用的dll.

问题是我的关于pascal的知识是空的,制作一个简单的程序看起来并不复杂,但我找不到关于如何导入和使用C/C++ DLL的好信息.

唯一没有用的是:http://www.drbob42.com/delphi/headconv.htm 我的真实代码:

帕斯卡尔:

funtion hello():Integer; external 'function' index 1;
...
Label1.Caption:=IntToStr(hello()); 
Run Code Online (Sandbox Code Playgroud)

C++ DLL头:

#ifndef function_H
#define function_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BUILDING_DLL
#define FUNCTION_DLL __declspec(dllexport)
#else
#define FUNCTION_DLL __declspec(dllimport)
#endif
 int __stdcall FUNCTION_DLL hello( );

#ifdef __cplusplus
}
#endif
#endif
Run Code Online (Sandbox Code Playgroud)

C++文件:

    #include <stdio.h>

#include "function.h"
  __stdcall int hello( )
{
return 8;
}
Run Code Online (Sandbox Code Playgroud)

但是当试图传递任何参数或做一些复杂的函数时,开始给出randoms数字.

这是新代码:Pascal:

function function1(t1:Integer):Integer; external 'function' index 1;  
...
entero:=8;
Label1.Caption:=IntToStr(function1(entero2));
Run Code Online (Sandbox Code Playgroud)

我还将c …

c++ delphi dll pascal freepascal

1
推荐指数
1
解决办法
2342
查看次数

标签 统计

c++ ×1

delphi ×1

dll ×1

freepascal ×1

pascal ×1