小编ben*_*min的帖子

(Delphi)使用函数指针参数调用DLL

我坚持调用外部DLL并将函数(指针)作为参数传递.我最近有一些不同的问题,传递一些参数到DLL,你帮助.希望,有人知道如何做到这一点....

这是DLL(cpp)中需要从Delphi调用的函数声明:


typedef void (*PTR_Allocate)(char**, unsigned long*);
typedef void (*PTR_Deallocate)(char*);

extern "C" export_dll_function void SetAllocateFunction(PTR_Allocate);
extern "C" export_dll_function void SetDeallocateFunction(PTR_Deallocate);

void Allocate(char** pbuffer, unsigned long* psize)
{
    *psize = *psize * 2;
    *pbuffer = new char[*psize];
}

void Deallocate(char* buffer)
{
    delete[] buffer;
}

能帮助我在Delphi(7)中重写这个吗?

这是我尝试过的,它抛出一个异常("外部异常"):


type
   PByte = ^TByte;
   TByte = array of byte;
   TFunc = function(var pbuffer: PByte; var psize: Cardinal): integer; cdecl;
   Procedure _SetAllocateFunction(var f: TFunc); cdecl;

implementation

function Allocate(var pbuffer: PByte; var psize: Cardinal): Integer; cdecl; …
Run Code Online (Sandbox Code Playgroud)

delphi dll pointers function

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

标签 统计

delphi ×1

dll ×1

function ×1

pointers ×1