我是用的STDCALL导出的,但是也不行,我把代码贴出来,帮忙看看,谢谢 Delphi 的代码,DLL的library Dlltest; uses SysUtils, Classes;{$R *.res}function Max(X:Integer;Y:Integer):integer;StdCall; begin if x>y then Result:=x; if x<y then Result:=Y; if x=y then Result:=x; end;function Min(X:Integer;Y:Integer):Integer;StdCall; begin if x>y then Result:=Y; if x<y then Result:=X; if x=y then Result:=x; end; exports Max, Min; begin end.C中的代码#include <stdio.h> #include<windows.h> void main(void) { int S; typedef int(*pMax)(int a,int b); typedef int(*pMin)(int a,int b); HINSTANCE hDLL; pMax Max; hDLL=LoadLibrary("Dlltest.dll"); Max=(pMax)GetProcAddress(hDLL,"Max"); S=Max(5,8); printf("比较的结果为%d\n",S); FreeLibrary(hDLL); }
主要用C++的语法罢了
就是 LoadLibrary GetProcAddress, FreeLibrary
这些函数。记住Delphi一定要用stdall导出。
Delphi 的代码,DLL的library Dlltest;
uses
SysUtils,
Classes;{$R *.res}function Max(X:Integer;Y:Integer):integer;StdCall;
begin
if x>y then Result:=x;
if x<y then Result:=Y;
if x=y then Result:=x;
end;function Min(X:Integer;Y:Integer):Integer;StdCall;
begin
if x>y then Result:=Y;
if x<y then Result:=X;
if x=y then Result:=x;
end;
exports
Max,
Min;
begin
end.C中的代码#include <stdio.h>
#include<windows.h>
void main(void)
{
int S;
typedef int(*pMax)(int a,int b);
typedef int(*pMin)(int a,int b);
HINSTANCE hDLL;
pMax Max;
hDLL=LoadLibrary("Dlltest.dll");
Max=(pMax)GetProcAddress(hDLL,"Max");
S=Max(5,8);
printf("比较的结果为%d\n",S);
FreeLibrary(hDLL);
}
typedef int(__stdcall *pMin)(int a,int b);
typedef int(WINAPI *pMin)(int a,int b);